Skip to content
Snippets Groups Projects
Commit 100b8578 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

various test improvements

parent ac4ee403
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ public class AllPduRoundTripTest
List<Pdu> pdusReceived = new ArrayList<>();
List<Pdu> pdusRead = new ArrayList<>();
PduFactory pduFactory;
PduRecorder recorder;
PduRecorder pduRecorder;
@BeforeAll
public static void beforeAllTests()
......@@ -176,8 +176,8 @@ public class AllPduRoundTripTest
}
private void setupSenderRecorder() throws Exception {
recorder = new PduRecorder(); // default mcaddr, port, logfile dir
disNetworkInterface = recorder.getDisThreadedNetIF();
pduRecorder = new PduRecorder(); // default network address, port, logfile dir
disNetworkInterface = pduRecorder.getDisThreadedNetworkInterface();
// When the DisThreadedNetworkInterface receives a pdu, a call is made to the
// everyTypeListeners which makes a lamba call back here to capture received
......@@ -191,14 +191,14 @@ public class AllPduRoundTripTest
}
};
disNetworkInterface.addListener(pduListener);
System.out.println("Recorder log at " + recorder.getLogFilePath());
System.out.println("Recorder log at " + pduRecorder.getLogFilePath());
}
/** Will shutdown the common send/receive network interface */
private void shutDownSenderRecorder() throws Exception
{
disNetworkInterface.removeListener(pduListener);
recorder.end();
pduRecorder.stop();
}
private void testForEquals() throws Exception
......@@ -212,8 +212,8 @@ public class AllPduRoundTripTest
private void getAllFromRecorder(Semaphore sem) throws Exception
{
sem.acquire();
Path path = Path.of(recorder.getLogFilePath()).getParent();
PduPlayer player = new PduPlayer(disNetworkInterface.getMulticastGroup(), disNetworkInterface.getDisPort(), path, false);
Path path = Path.of(pduRecorder.getLogFilePath()).getParent();
PduPlayer player = new PduPlayer(disNetworkInterface.getAddress(), disNetworkInterface.getPort(), path, false);
player.addRawListener(ba -> {
if (ba != null) {
Pdu pdu = pduFactory.createPdu(ba);
......
......@@ -52,8 +52,7 @@ public class BitFieldRoundTripTest
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
disNetworkInterface.close();
}
@Test
......
......@@ -46,8 +46,7 @@ public class CommentPdusTest
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
disNetworkInterface.close();
}
/** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */
......
......@@ -50,8 +50,7 @@ public class DataQueryPduRoundTripTest
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
disNetworkInterface.close();
}
private static int REQUEST_ID = 0x00112233;
......
......@@ -49,8 +49,7 @@ public class FixedAndVariableDatumRoundTripTest
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
disNetworkInterface.close();
}
private static final FixedDatum fixedDatum1 = new FixedDatum();
......
......@@ -90,8 +90,7 @@ abstract public class PduTest
public void tearDown()
{
disNetworkInterface.removeListener(pduListener);
disNetworkInterface.kill();
disNetworkInterface = null;
disNetworkInterface.close();
try // additional sleep, allowing teardown to proceed
{
Thread.sleep(getThreadSleepInterval());
......
......@@ -36,10 +36,10 @@ public class SignalPdusTest {
static DisThreadedNetworkInterface disNetworkInterface;
static DisThreadedNetworkInterface.PduListener pduListener;
static List<Pdu> receivedPdus;
static PduRecorder recorder;
static PduRecorder pduRecorder;
static Semaphore mutex;
static PduFactory pduFac;
static PduFactory pduFactory;
static List<Pdu> sentPdus;
byte[] bufferByteArray;
int size;
......@@ -48,8 +48,8 @@ public class SignalPdusTest {
public static void setUpClass() throws IOException {
System.out.println("SignalPdusTest");
recorder = new PduRecorder(); // default dir
disNetworkInterface = recorder.getDisThreadedNetIF();
pduRecorder = new PduRecorder(); // default dir
disNetworkInterface = pduRecorder.getDisThreadedNetworkInterface();
pduListener = new DisThreadedNetworkInterface.PduListener() {
@Override
public void incomingPdu(Pdu pdu) {
......@@ -60,24 +60,24 @@ public class SignalPdusTest {
mutex = new Semaphore(1);
sentPdus = new ArrayList<>();
sentPdus = new ArrayList<>();
receivedPdus = new ArrayList<>();
pduFac = new PduFactory();
pduFactory = new PduFactory();
Pdu pdu = pduFac.makeSignalPdu(); // empty contents
Pdu pdu = pduFactory.makeSignalPdu(); // empty contents
sentPdus.add(pdu);
pdu = pduFac.makeSignalPdu();
pdu = pduFactory.makeSignalPdu();
((SignalPdu) pdu).setEncodingScheme((short) 0x1111);
((SignalPdu) pdu).setSampleRate(0x22222222);
((SignalPdu) pdu).setSamples((short) 0x3333);
((SignalPdu) pdu).setData("SignalPdu-testdata".getBytes());
sentPdus.add(pdu);
pdu = pduFac.makeIntercomSignalPdu();
pdu = pduFactory.makeIntercomSignalPdu();
sentPdus.add(pdu);
pdu = pduFac.makeIntercomSignalPdu();
pdu = pduFactory.makeIntercomSignalPdu();
((IntercomSignalPdu) pdu).setEncodingScheme((short) 0x1111);
((IntercomSignalPdu) pdu).setSampleRate(0x22222222);
((IntercomSignalPdu) pdu).setSamples((short) 0x3333);
......@@ -102,7 +102,7 @@ public class SignalPdusTest {
@AfterEach
public void tearDown() throws IOException {
disNetworkInterface.removeListener(pduListener);
recorder.end(); // kills the disNetworkInterface as well
pduRecorder.stop(); // kills the disNetworkInterface as well
}
@Test
......@@ -118,7 +118,7 @@ public class SignalPdusTest {
assertTrue(size > 0, "Unmarshalling error: Unmarshalled size: " + size);
// This also unmarshalls the pdu
pdu = pduFac.createPdu(bufferByteArray);
pdu = pduFactory.createPdu(bufferByteArray);
assertNotNull(pdu, "Unmarshalling error " + pdu);
} catch (Exception ex) {
Logger.getLogger(SignalPdusTest.class.getName()).log(Level.SEVERE, null, ex);
......@@ -138,12 +138,12 @@ public class SignalPdusTest {
Path path = Path.of("./pduLog");
// Note: the player will playback all log files in the given path
PduPlayer player = new PduPlayer(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS, DisThreadedNetworkInterface.DEFAULT_DIS_PORT, path, false);
player.addRawListener(ba -> {
PduPlayer pduPlayer = new PduPlayer(DisThreadedNetworkInterface.DEFAULT_DIS_ADDRESS, DisThreadedNetworkInterface.DEFAULT_DIS_PORT, path, false);
pduPlayer.addRawListener(ba -> {
if (ba != null)
assertNotNull(pduFac.createPdu(ba), "PDU creation failure");
assertNotNull(pduFactory.createPdu(ba), "PDU creation failure");
else {
player.end();
pduPlayer.end();
mutex.release();
}
});
......
......@@ -62,7 +62,7 @@ public class X3dInterpolatorsTest {
Path path = Path.of("./pduLog");
// Note: the player will playback all log files in the given path
PduPlayer pduPlayer = new PduPlayer(DisThreadedNetworkInterface.DEFAULT_MULTICAST_ADDRESS, DisThreadedNetworkInterface.DEFAULT_DIS_PORT, path, true);
PduPlayer pduPlayer = new PduPlayer(DisThreadedNetworkInterface.DEFAULT_DIS_ADDRESS, DisThreadedNetworkInterface.DEFAULT_DIS_PORT, path, true);
pduPlayer.addRawListener(ba -> {
if (ba == null) {
pduPlayer.end();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment