Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
52e7f3a5
Commit
52e7f3a5
authored
5 years ago
by
terry-norbraten
Browse files
Options
Downloads
Patches
Plain Diff
align send w/ Signal test
parent
a3bd809d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/edu/nps/moves/dis7/AllPduRoundTripTest.java
+106
-117
106 additions, 117 deletions
test/edu/nps/moves/dis7/AllPduRoundTripTest.java
with
106 additions
and
117 deletions
test/edu/nps/moves/dis7/AllPduRoundTripTest.java
+
106
−
117
View file @
52e7f3a5
...
@@ -17,14 +17,13 @@ package edu.nps.moves.dis7;
...
@@ -17,14 +17,13 @@ package edu.nps.moves.dis7;
* @version $Id$
* @version $Id$
*/
*/
import
edu.nps.moves.dis7.enumerations.Country
;
import
edu.nps.moves.dis7.enumerations.Country
;
import
edu.nps.moves.dis7.enumerations.DISPDUType
;
import
edu.nps.moves.dis7.utilities.DisThreadedNetIF
;
import
edu.nps.moves.dis7.utilities.DisThreadedNetIF
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
edu.nps.moves.dis7.utilities.stream.PduPlayer
;
import
edu.nps.moves.dis7.utilities.stream.PduPlayer
;
import
edu.nps.moves.dis7.utilities.stream.PduRecorder
;
import
edu.nps.moves.dis7.utilities.stream.PduRecorder
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.util.
HashMap
;
import
java.util.
ArrayList
;
import
java.util.
Map
;
import
java.util.
List
;
import
java.util.concurrent.Semaphore
;
import
java.util.concurrent.Semaphore
;
import
org.junit.jupiter.api.*
;
import
org.junit.jupiter.api.*
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
...
@@ -32,7 +31,13 @@ import static org.junit.jupiter.api.Assertions.*;
...
@@ -32,7 +31,13 @@ import static org.junit.jupiter.api.Assertions.*;
@DisplayName
(
"All Pdu Round Trip Test"
)
@DisplayName
(
"All Pdu Round Trip Test"
)
public
class
AllPduRoundTripTest
public
class
AllPduRoundTripTest
{
{
private
PduFactory
pduFactory
;
DisThreadedNetIF
disnetworking
;
DisThreadedNetIF
.
PduListener
lis
;
List
<
Pdu
>
pdusSent
=
new
ArrayList
<>();
List
<
Pdu
>
pdusReceived
=
new
ArrayList
<>();
List
<
Pdu
>
pdusRead
=
new
ArrayList
<>();
PduFactory
pduFactory
;
PduRecorder
recorder
;
@BeforeAll
@BeforeAll
public
static
void
beforeAllTests
()
public
static
void
beforeAllTests
()
...
@@ -64,90 +69,89 @@ public class AllPduRoundTripTest
...
@@ -64,90 +69,89 @@ public class AllPduRoundTripTest
pduFactory
=
new
PduFactory
(
Country
.
PHILIPPINES_PHL
,
(
byte
)
11
,
(
byte
)
22
,
(
short
)
33
,
true
);
pduFactory
=
new
PduFactory
(
Country
.
PHILIPPINES_PHL
,
(
byte
)
11
,
(
byte
)
22
,
(
short
)
33
,
true
);
sendOnePdu
(
pduFactory
.
makeAcknowledgePdu
());
pdusSent
.
add
(
pduFactory
.
makeAcknowledgePdu
());
sendOnePdu
(
pduFactory
.
makeAcknowledgeReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeAcknowledgeReliablePdu
());
sendOnePdu
(
pduFactory
.
makeActionRequestPdu
());
pdusSent
.
add
(
pduFactory
.
makeActionRequestPdu
());
sendOnePdu
(
pduFactory
.
makeActionRequestReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeActionRequestReliablePdu
());
sendOnePdu
(
pduFactory
.
makeActionResponsePdu
());
pdusSent
.
add
(
pduFactory
.
makeActionResponsePdu
());
sendOnePdu
(
pduFactory
.
makeActionResponseReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeActionResponseReliablePdu
());
sendOnePdu
(
pduFactory
.
makeAggregateStatePdu
());
pdusSent
.
add
(
pduFactory
.
makeAggregateStatePdu
());
sendOnePdu
(
pduFactory
.
makeAppearancePdu
());
pdusSent
.
add
(
pduFactory
.
makeAppearancePdu
());
sendOnePdu
(
pduFactory
.
makeArealObjectStatePdu
());
pdusSent
.
add
(
pduFactory
.
makeArealObjectStatePdu
());
sendOnePdu
(
pduFactory
.
makeArticulatedPartsPdu
());
pdusSent
.
add
(
pduFactory
.
makeArticulatedPartsPdu
());
sendOnePdu
(
pduFactory
.
makeAttributePdu
());
pdusSent
.
add
(
pduFactory
.
makeAttributePdu
());
sendOnePdu
(
pduFactory
.
makeCollisionElasticPdu
());
pdusSent
.
add
(
pduFactory
.
makeCollisionElasticPdu
());
sendOnePdu
(
pduFactory
.
makeCollisionPdu
());
pdusSent
.
add
(
pduFactory
.
makeCollisionPdu
());
sendOnePdu
(
pduFactory
.
makeCommentPdu
());
pdusSent
.
add
(
pduFactory
.
makeCommentPdu
());
sendOnePdu
(
pduFactory
.
makeCommentReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeCommentReliablePdu
());
sendOnePdu
(
pduFactory
.
makeCreateEntityPdu
());
pdusSent
.
add
(
pduFactory
.
makeCreateEntityPdu
());
sendOnePdu
(
pduFactory
.
makeCreateEntityReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeCreateEntityReliablePdu
());
sendOnePdu
(
pduFactory
.
makeDataPdu
());
pdusSent
.
add
(
pduFactory
.
makeDataPdu
());
sendOnePdu
(
pduFactory
.
makeDataQueryPdu
());
pdusSent
.
add
(
pduFactory
.
makeDataQueryPdu
());
sendOnePdu
(
pduFactory
.
makeDataQueryReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeDataQueryReliablePdu
());
sendOnePdu
(
pduFactory
.
makeDataReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeDataReliablePdu
());
sendOnePdu
(
pduFactory
.
makeDesignatorPdu
());
pdusSent
.
add
(
pduFactory
.
makeDesignatorPdu
());
sendOnePdu
(
pduFactory
.
makeDetonationPdu
());
pdusSent
.
add
(
pduFactory
.
makeDetonationPdu
());
sendOnePdu
(
pduFactory
.
makeDirectedEnergyFirePdu
());
pdusSent
.
add
(
pduFactory
.
makeDirectedEnergyFirePdu
());
sendOnePdu
(
pduFactory
.
makeElectronicEmissionsPdu
());
pdusSent
.
add
(
pduFactory
.
makeElectronicEmissionsPdu
());
sendOnePdu
(
pduFactory
.
makeEntityDamageStatusPdu
());
pdusSent
.
add
(
pduFactory
.
makeEntityDamageStatusPdu
());
sendOnePdu
(
pduFactory
.
makeEntityStatePdu
());
pdusSent
.
add
(
pduFactory
.
makeEntityStatePdu
());
sendOnePdu
(
pduFactory
.
makeEntityStateUpdatePdu
());
pdusSent
.
add
(
pduFactory
.
makeEntityStateUpdatePdu
());
sendOnePdu
(
pduFactory
.
makeEnvironmentalProcessPdu
());
pdusSent
.
add
(
pduFactory
.
makeEnvironmentalProcessPdu
());
sendOnePdu
(
pduFactory
.
makeEventReportPdu
());
pdusSent
.
add
(
pduFactory
.
makeEventReportPdu
());
sendOnePdu
(
pduFactory
.
makeEventReportReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeEventReportReliablePdu
());
sendOnePdu
(
pduFactory
.
makeFirePdu
());
pdusSent
.
add
(
pduFactory
.
makeFirePdu
());
sendOnePdu
(
pduFactory
.
makeGriddedDataPdu
());
pdusSent
.
add
(
pduFactory
.
makeGriddedDataPdu
());
sendOnePdu
(
pduFactory
.
makeIffPdu
());
pdusSent
.
add
(
pduFactory
.
makeIffPdu
());
sendOnePdu
(
pduFactory
.
makeInformationOperationsReportPdu
());
pdusSent
.
add
(
pduFactory
.
makeInformationOperationsReportPdu
());
sendOnePdu
(
pduFactory
.
makeInformationOperationsActionPdu
());
pdusSent
.
add
(
pduFactory
.
makeInformationOperationsActionPdu
());
sendOnePdu
(
pduFactory
.
makeIntercomControlPdu
());
pdusSent
.
add
(
pduFactory
.
makeIntercomControlPdu
());
sendOnePdu
(
pduFactory
.
makeIntercomSignalPdu
());
pdusSent
.
add
(
pduFactory
.
makeIntercomSignalPdu
());
sendOnePdu
(
pduFactory
.
makeIsGroupOfPdu
());
pdusSent
.
add
(
pduFactory
.
makeIsGroupOfPdu
());
sendOnePdu
(
pduFactory
.
makeIsPartOfPdu
());
pdusSent
.
add
(
pduFactory
.
makeIsPartOfPdu
());
sendOnePdu
(
pduFactory
.
makeLEDetonationPdu
());
pdusSent
.
add
(
pduFactory
.
makeLEDetonationPdu
());
sendOnePdu
(
pduFactory
.
makeLEFirePdu
());
pdusSent
.
add
(
pduFactory
.
makeLEFirePdu
());
sendOnePdu
(
pduFactory
.
makeLinearObjectStatePdu
());
pdusSent
.
add
(
pduFactory
.
makeLinearObjectStatePdu
());
sendOnePdu
(
pduFactory
.
makeMinefieldDataPdu
());
pdusSent
.
add
(
pduFactory
.
makeMinefieldDataPdu
());
sendOnePdu
(
pduFactory
.
makeMinefieldQueryPdu
());
pdusSent
.
add
(
pduFactory
.
makeMinefieldQueryPdu
());
sendOnePdu
(
pduFactory
.
makeMinefieldResponseNackPdu
());
pdusSent
.
add
(
pduFactory
.
makeMinefieldResponseNackPdu
());
sendOnePdu
(
pduFactory
.
makeMinefieldStatePdu
());
pdusSent
.
add
(
pduFactory
.
makeMinefieldStatePdu
());
sendOnePdu
(
pduFactory
.
makePointObjectStatePdu
());
pdusSent
.
add
(
pduFactory
.
makePointObjectStatePdu
());
sendOnePdu
(
pduFactory
.
makeReceiverPdu
());
pdusSent
.
add
(
pduFactory
.
makeReceiverPdu
());
sendOnePdu
(
pduFactory
.
makeRecordQueryReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeRecordQueryReliablePdu
());
sendOnePdu
(
pduFactory
.
makeRecordReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeRecordReliablePdu
());
sendOnePdu
(
pduFactory
.
makeRemoveEntityPdu
());
pdusSent
.
add
(
pduFactory
.
makeRemoveEntityPdu
());
sendOnePdu
(
pduFactory
.
makeRemoveEntityReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeRemoveEntityReliablePdu
());
sendOnePdu
(
pduFactory
.
makeRepairCompletePdu
());
pdusSent
.
add
(
pduFactory
.
makeRepairCompletePdu
());
sendOnePdu
(
pduFactory
.
makeRepairResponsePdu
());
pdusSent
.
add
(
pduFactory
.
makeRepairResponsePdu
());
sendOnePdu
(
pduFactory
.
makeResupplyCancelPdu
());
pdusSent
.
add
(
pduFactory
.
makeResupplyCancelPdu
());
sendOnePdu
(
pduFactory
.
makeResupplyOfferPdu
());
pdusSent
.
add
(
pduFactory
.
makeResupplyOfferPdu
());
sendOnePdu
(
pduFactory
.
makeResupplyReceivedPdu
());
pdusSent
.
add
(
pduFactory
.
makeResupplyReceivedPdu
());
sendOnePdu
(
pduFactory
.
makeSeesPdu
());
pdusSent
.
add
(
pduFactory
.
makeSeesPdu
());
sendOnePdu
(
pduFactory
.
makeServiceRequestPdu
());
pdusSent
.
add
(
pduFactory
.
makeServiceRequestPdu
());
sendOnePdu
(
pduFactory
.
makeSetDataPdu
());
pdusSent
.
add
(
pduFactory
.
makeSetDataPdu
());
sendOnePdu
(
pduFactory
.
makeSetDataReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeSetDataReliablePdu
());
sendOnePdu
(
pduFactory
.
makeSetRecordReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeSetRecordReliablePdu
());
sendOnePdu
(
pduFactory
.
makeSignalPdu
());
pdusSent
.
add
(
pduFactory
.
makeSignalPdu
());
sendOnePdu
(
pduFactory
.
makeStartResumePdu
());
pdusSent
.
add
(
pduFactory
.
makeStartResumePdu
());
sendOnePdu
(
pduFactory
.
makeStartResumeReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeStartResumeReliablePdu
());
sendOnePdu
(
pduFactory
.
makeStopFreezePdu
());
pdusSent
.
add
(
pduFactory
.
makeStopFreezePdu
());
sendOnePdu
(
pduFactory
.
makeStopFreezeReliablePdu
());
pdusSent
.
add
(
pduFactory
.
makeStopFreezeReliablePdu
());
sendOnePdu
(
pduFactory
.
makeTransferOwnershipPdu
());
pdusSent
.
add
(
pduFactory
.
makeTransferOwnershipPdu
());
sendOnePdu
(
pduFactory
.
makeTransmitterPdu
());
pdusSent
.
add
(
pduFactory
.
makeTransmitterPdu
());
sendOnePdu
(
pduFactory
.
makeTspiPdu
());
pdusSent
.
add
(
pduFactory
.
makeTspiPdu
());
sendOnePdu
(
pduFactory
.
makeUnderwaterAcousticPdu
());
pdusSent
.
add
(
pduFactory
.
makeUnderwaterAcousticPdu
());
//sleep(100L); // go sender/receiver go! is this enough time to receive?
pdusSent
.
forEach
(
p
->
{
disnetworking
.
send
(
p
);
// TODO is there a more reliable way to determine whether receiver is complete?
sleep
(
1
l
);
// give receiver time to process
});
shutDownSenderRecorder
();
shutDownSenderRecorder
();
System
.
out
.
println
(
"pduReceivedMap.size()="
+
pduReceivedMap
.
size
()
+
", pduSentMap.size()="
+
pduSentMap
.
size
()
+
System
.
out
.
println
(
"pduReceivedMap.size()="
+
pdusReceived
.
size
()
+
", pduSentMap.size()="
+
pdusSent
.
size
()
+
", match="
+
(
pduReceivedMap
.
size
()
==
pduSentMap
.
size
()));
", match="
+
(
pdusReceived
.
size
()
==
pdusSent
.
size
()));
assertEquals
(
pduReceivedMap
.
size
(),
pduSentMap
.
size
(),
"No pdus, or not all sent pdus, received"
);
testForEquals
();
testForEquals
();
Semaphore
mutex
=
new
Semaphore
(
1
);
Semaphore
mutex
=
new
Semaphore
(
1
);
...
@@ -164,22 +168,6 @@ public class AllPduRoundTripTest
...
@@ -164,22 +168,6 @@ public class AllPduRoundTripTest
assertNull
(
ex
,
"Exception should be null if successful creation of all objects"
);
assertNull
(
ex
,
"Exception should be null if successful creation of all objects"
);
}
}
private
Map
<
DISPDUType
,
Pdu
>
pduSentMap
=
new
HashMap
<>();
private
Map
<
DISPDUType
,
Pdu
>
pduReceivedMap
=
new
HashMap
<>();
private
Map
<
DISPDUType
,
Pdu
>
pduReadMap
=
new
HashMap
<>();
DisThreadedNetIF
disnetworking
;
PduRecorder
recorder
;
private
void
sendOnePdu
(
Pdu
pdu
)
{
pduSentMap
.
put
(
pdu
.
getPduType
(),
pdu
);
if
(
pdu
.
getPduType
()
==
DISPDUType
.
OTHER
)
System
.
out
.
println
(
"*** Note: DISPDUType.OTHER not supported"
);
disnetworking
.
send
(
pdu
);
sleep
(
100L
);
// TODO debugging
}
private
void
setupSenderRecorder
()
throws
Exception
private
void
setupSenderRecorder
()
throws
Exception
{
{
...
@@ -187,24 +175,29 @@ public class AllPduRoundTripTest
...
@@ -187,24 +175,29 @@ public class AllPduRoundTripTest
disnetworking
=
recorder
.
getDisThreadedNetIF
();
disnetworking
=
recorder
.
getDisThreadedNetIF
();
// When the DisThreadedNetIF receives a pdu, a call is made to the
// When the DisThreadedNetIF receives a pdu, a call is made to the
// everyTypeListeners which makes a lamba call back here to
record
received
// everyTypeListeners which makes a lamba call back here to
capture
received
// pdus
// pdus
disnetworking
.
addListener
(
pdu
->
{
lis
=
new
DisThreadedNetIF
.
PduListener
()
{
pduReceivedMap
.
put
(
pdu
.
getPduType
(),
pdu
);
@Override
});
public
void
incomingPdu
(
Pdu
pdu
)
{
pdusReceived
.
add
(
pdu
);
}
};
disnetworking
.
addListener
(
lis
);
System
.
out
.
println
(
"Recorder log at "
+
recorder
.
getLogFile
());
System
.
out
.
println
(
"Recorder log at "
+
recorder
.
getLogFile
());
}
}
/** Will shutdown the common send/receive network interface */
/** Will shutdown the common send/receive network interface */
private
void
shutDownSenderRecorder
()
throws
Exception
private
void
shutDownSenderRecorder
()
throws
Exception
{
{
disnetworking
.
removeListener
(
lis
);
recorder
.
end
();
recorder
.
end
();
}
}
private
void
testForEquals
()
throws
Exception
private
void
testForEquals
()
throws
Exception
{
{
assertEquals
(
pduSent
Map
.
size
(),
pduReceived
Map
.
size
(),
"Different number of pdus received than sent"
);
assertEquals
(
pdu
s
Sent
.
size
(),
pdu
s
Received
.
size
(),
"Different number of pdus received than sent"
);
assertIterableEquals
(
pduSent
Map
.
keySet
()
,
pduReceived
Map
.
keySet
()
,
"Sent and received pdus not identical"
);
assertIterableEquals
(
pdu
s
Sent
,
pdu
s
Received
,
"Sent and received pdus not identical"
);
// TODO is this sufficient? has each PDU value been compared as well?
// TODO is this sufficient? has each PDU value been compared as well?
}
}
...
@@ -218,34 +211,30 @@ public class AllPduRoundTripTest
...
@@ -218,34 +211,30 @@ public class AllPduRoundTripTest
player
.
addRawListener
(
ba
->
{
player
.
addRawListener
(
ba
->
{
if
(
ba
!=
null
)
{
if
(
ba
!=
null
)
{
Pdu
pdu
=
pduFactory
.
createPdu
(
ba
);
Pdu
pdu
=
pduFactory
.
createPdu
(
ba
);
pduRead
Map
.
put
(
pdu
.
getPduType
(),
pdu
);
pdu
s
Read
.
add
(
pdu
);
}
}
else
{
else
{
player
.
end
();
player
.
end
();
sem
.
release
();
sem
.
release
();
}
}
});
});
player
.
startResume
();
}
}
private
void
testRecorderForEquals
()
throws
Exception
private
void
testRecorderForEquals
()
throws
Exception
{
{
assertEquals
(
pduSent
Map
.
size
(),
pduRead
Map
.
size
(),
"Different number of pdus sent than read"
);
assertEquals
(
pdu
s
Sent
.
size
(),
pdu
s
Read
.
size
(),
"Different number of pdus sent than read"
);
assertIterableEquals
(
pduSent
Map
.
keySet
()
,
pduRead
Map
.
keySet
()
,
"Sent and read pdus not identical"
);
assertIterableEquals
(
pdu
s
Sent
,
pdu
s
Read
,
"Sent and read pdus not identical"
);
// TODO is this sufficient? has each PDU value been compared as well?
// TODO is this sufficient? has each PDU value been compared as well?
}
}
//@formatter:off
private
static
void
sleep
(
long
ms
)
{
private
void
sleep
(
long
ms
)
{
try
{
try
{
Thread
.
sleep
(
ms
);
Thread
.
sleep
(
ms
);
}
catch
(
InterruptedException
ex
)
{
fail
(
"NetIF Send: "
+
ex
);
}
}
catch
(
InterruptedException
ex
)
{}
}
}
//@formatter:on
public
static
void
main
(
String
[]
args
)
public
static
void
main
(
String
[]
args
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment