+
+ private static void addSyncMatch(SynchronizationAlgorithm algo, ITmfTrace sender, long sendTs, ITmfTrace receiver, long receiveTs) {
+ algo.addMatch(
+ new TmfEventDependency(
+ new TmfSyncEventStub(sender, new TmfTimestamp(sendTs)),
+ new TmfSyncEventStub(receiver, new TmfTimestamp(receiveTs))
+ ));
+ }
+
+ /**
+ * Testing the serialization of the fully incremental synchronization
+ * algorithm
+ */
+ @Test
+ public void testFullyIncrementalSerialization() {
+
+ /* Do a run of synchronization and check the results */
+ SynchronizationAlgorithm syncAlgo = SynchronizationAlgorithmFactory.getFullyIncrementalAlgorithm();
+
+ syncAlgo.init(fTraces);
+
+ addSyncMatch(syncAlgo, t2, 1, t1, 1);
+ addSyncMatch(syncAlgo, t1, 1, t2, 3);
+ addSyncMatch(syncAlgo, t2, 2, t1, 3);
+ addSyncMatch(syncAlgo, t1, 3, t2, 5);
+ addSyncMatch(syncAlgo, t1, 4, t2, 8);
+ addSyncMatch(syncAlgo, t2, 4, t1, 5);
+ addSyncMatch(syncAlgo, t2, 4, t1, 6);
+ addSyncMatch(syncAlgo, t1, 6, t2, 7);
+
+ ITmfTimestampTransform tt2 = syncAlgo.getTimestampTransform(t2);
+ ITmfTimestampTransform tt1 = syncAlgo.getTimestampTransform(t1);
+
+ assertEquals(SyncQuality.ACCURATE, syncAlgo.getSynchronizationQuality(t1, t2));
+ assertEquals(syncAlgo.getTimestampTransform(t1.getHostId()), tt1);
+ assertEquals(TimestampTransformFactory.getDefaultTransform(), tt1);
+ assertEquals(syncAlgo.getTimestampTransform(t2.getHostId()), tt2);
+
+ /* Serialize the object */
+ String filePath = null;
+ try {
+ File temp = File.createTempFile("serialSyncAlgo", ".tmp");
+ filePath = temp.getAbsolutePath();
+ } catch (IOException e) {
+ fail("Could not create temporary file for serialization");
+ }
+ assertNotNull(filePath);
+
+ try (FileOutputStream fileOut = new FileOutputStream(filePath);
+ ObjectOutputStream out = new ObjectOutputStream(fileOut);) {
+ out.writeObject(syncAlgo);
+
+ } catch (IOException e) {
+ fail("Error serializing the synchronization algorithm " + e.getMessage());
+ }
+
+ SynchronizationAlgorithm deserialAlgo = null;
+ /* De-Serialize the object */
+ try (FileInputStream fileIn = new FileInputStream(filePath);
+ ObjectInputStream in = new ObjectInputStream(fileIn);) {
+ deserialAlgo = (SynchronizationAlgorithm) in.readObject();
+ } catch (IOException | ClassNotFoundException e) {
+ fail("Error de-serializing the synchronization algorithm " + e.getMessage());
+ }
+
+ /* Check that the deserialize algorithm is equivalent to original */
+ assertNotNull(deserialAlgo);
+ assertTrue(deserialAlgo instanceof SyncAlgorithmFullyIncremental);
+ assertEquals(SyncQuality.ACCURATE, deserialAlgo.getSynchronizationQuality(t1, t2));
+ assertEquals(tt1, deserialAlgo.getTimestampTransform(t1));
+ assertEquals(tt2, deserialAlgo.getTimestampTransform(t2));
+
+ }
+