Skip to content

Commit

Permalink
#29 Create software release 1.0.2-RELEASE. Added test for monitor dis…
Browse files Browse the repository at this point in the history
…connect behaviour. Cleaned up gradle file.
  • Loading branch information
simondelabici committed Jul 9, 2018
1 parent a94c498 commit 03925c7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'signing'
group = 'org.epics'
archivesBaseName = 'ca'
sourceCompatibility = 10
version = '1.0.2-RELEASE'
version = '1.0.2-SNAPSHOT'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

Expand Down Expand Up @@ -44,6 +44,17 @@ dependencies {
compile 'com.lmax:disruptor:3.4.2'
compile 'com.lmax:disruptor:3.4.2:javadoc'

// Needed for parameter validation (als0 the stopwatch timing class
// that is used in testing).
compile 'org.apache.commons:commons-lang3:3.7'

// Support for improved logging
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.slf4j:slf4j-jdk14:1.7.25'

// Supports for documenting Thread-Safety
compile 'com.github.stephenc.jcip:jcip-annotations:1.0-1'

// Supports unit and integration tests
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testCompile('org.junit.jupiter:junit-jupiter-api:5.2.0:javadoc')
Expand All @@ -60,15 +71,6 @@ dependencies {
testCompile 'org.epics:jca:2.3.6'
testCompile 'org.epics:jca:2.3.6:javadoc'

// Needed for stopwatch timing class
compile 'org.apache.commons:commons-lang3:3.7'

// Support for improved logging
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.slf4j:slf4j-jdk14:1.7.25'

// Supports documenting Thread-Safety
compile 'com.github.stephenc.jcip:jcip-annotations:1.0-1'
}

test {
Expand Down
67 changes: 38 additions & 29 deletions src/test/java/org/epics/ca/ChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.epics.ca.data.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
Expand All @@ -32,6 +36,12 @@ public class ChannelTest
private CAJTestServer server;
private static final int TIMEOUT_SEC = 5;

@BeforeAll
static void beforeAll()
{
System.setProperty( "java.util.logging.SimpleFormatter.format", "%1$tF %1$tT.%1$tL %4$s %5$s%6$s%n");
}

@BeforeEach
protected void setUp() throws Exception
{
Expand Down Expand Up @@ -482,38 +492,36 @@ public void testGraphicEnum() throws Throwable
@Test
public void testMonitorDisconnectionBehaviour() throws InterruptedException
{
try ( Channel<Integer> channel = context.createChannel ("test:db_ok", Integer.class) )
try ( Channel<Integer> channel = context.createChannel ("adc01", Integer.class) )
{
channel.addConnectionListener( (c,h) -> logger.info ( "Channel {}, new connection state is: {} ", c.getName(), c.getConnectionState() ) );
channel.connect();

Consumer<Timestamped> consumer = new Consumer<Timestamped>()
{
@Override
public void accept( Timestamped integerMetadata )
{
if ( integerMetadata == null )
{
throw new NullPointerException();
// logger.info( "null was sent " );
//return;
}

long timestamp = integerMetadata.getNanos();
Integer value = (Integer) integerMetadata.getValue();
logger.info( "accept called at time {} with value {}", timestamp, value );
}
};

Monitor<Timestamped> mon = channel.addMonitor( Timestamped.class, consumer );

//channel.close();
Thread.sleep( 120_000 );
logger.info( "Closing...");
channel.close();
Thread.sleep( 5000 );
logger.info( "Closed." );
channel.addConnectionListener( (c,h) -> logger.info ( "Channel {}, new connection state is: {} ", c.getName(), c.getConnectionState() ) );

// Connect to some channel and get the default value (= value on creation) for the test PV
channel.connect();
final int defautAdcValue = channel.get();

// Change the PV value to something else, allow the change to propagate
// then verify that the expected value was receved.
final int testValue = 99;
channel.put( testValue );
final Consumer<Integer> consumer = Mockito.mock( Consumer.class );
final Monitor<Integer> monitor = channel.addValueMonitor( consumer );
Thread.sleep( 1_000 );
Mockito.verify( consumer, Mockito.times( 1) ).accept( testValue );

// Destroy the test server which will create a channel disconnection event.
// Verify that the monitor did not receive a new update
server.destroy();
Thread.sleep( 1_000 );
Mockito.verifyNoMoreInteractions( consumer );

// Now recreate the server and check that the monitor received an update with the default value
// for this PV
server = new CAJTestServer ();
server.runInSeparateThread ();
Thread.sleep( 1_000 );
Mockito.verify( consumer, Mockito.times( 1 ) ).accept( defautAdcValue );
}
}

Expand Down Expand Up @@ -635,4 +643,5 @@ public void testLargeArray() throws Throwable
}



}

0 comments on commit 03925c7

Please sign in to comment.