Search in sources :

Example 1 with SyncAlgorithmFullyIncremental

use of org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental in project tracecompass by tracecompass.

the class TmfExperimentTest method testWithMultiHostClockOffset.

/**
 * Tests that opening an experiment whose traces already have a
 * synchronization formula will not eliminate that formula. This test makes
 * the supposition that the experiment was synchronized and the
 * synchronization added the clock offset correction to the total formula.
 */
@Test
public void testWithMultiHostClockOffset() {
    // Data for this specific test
    String hostId = "Test Host 1";
    String hostId2 = "Test Host 2";
    long minOffset = 2000;
    long offset = 1000;
    String clockOffset = "clock_offset";
    ITmfTimestampTransform tt1 = TimestampTransformFactory.createLinear(2.0, offset / 2);
    ITmfTimestampTransform tt2 = TimestampTransformFactory.createLinear(2.0, -offset / 2);
    ITmfTimestampTransform tt3 = TimestampTransformFactory.createWithOffset(offset);
    ITmfTrace t1 = new TestTrace("t1") {

        @Override
        @NonNull
        public String getHostId() {
            return hostId;
        }

        @Override
        @NonNull
        public Map<@NonNull String, @NonNull String> getProperties() {
            return ImmutableMap.of(clockOffset, String.valueOf(minOffset));
        }
    };
    t1.setTimestampTransform(tt1);
    ITmfTrace t2 = new TestTrace("t2") {

        @Override
        @NonNull
        public String getHostId() {
            return hostId;
        }

        @Override
        @NonNull
        public Map<@NonNull String, @NonNull String> getProperties() {
            return ImmutableMap.of(clockOffset, String.valueOf(minOffset + offset));
        }
    };
    t2.setTimestampTransform(tt2);
    ITmfTrace t3 = new TmfXmlTraceStubNs() {

        @Override
        @NonNull
        public String getHostId() {
            return hostId2;
        }
    };
    t3.setTimestampTransform(tt3);
    TmfExperiment exp = new TmfExperimentStub(EXPERIMENT, new ITmfTrace[] { t1, t2, t3 }, BLOCK_SIZE) {

        @Override
        public SynchronizationAlgorithm synchronizeTraces() {
            return new SyncAlgorithmFullyIncremental() {

                private static final long serialVersionUID = 4206172498287480153L;

                @Override
                public ITmfTimestampTransform getTimestampTransform(String h) {
                    if (hostId.equals(h)) {
                        return TimestampTransformFactory.createLinear(2.0, 0);
                    }
                    return tt3;
                }
            };
        }
    };
    try {
        assertEquals(tt1, t1.getTimestampTransform());
        assertEquals(tt2, t2.getTimestampTransform());
        assertEquals(tt3, t3.getTimestampTransform());
    } finally {
        exp.dispose();
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) SyncAlgorithmFullyIncremental(org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) TmfTestTrace(org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 2 with SyncAlgorithmFullyIncremental

use of org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental in project tracecompass by tracecompass.

the class SyncTest method testFullyIncrementalSerialization.

/**
 * 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));
}
Also used : FileOutputStream(java.io.FileOutputStream) SyncAlgorithmFullyIncremental(org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental) IOException(java.io.IOException) ITmfTimestampTransform(org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) SynchronizationAlgorithm(org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

SyncAlgorithmFullyIncremental (org.eclipse.tracecompass.internal.tmf.core.synchronization.SyncAlgorithmFullyIncremental)2 ITmfTimestampTransform (org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 SynchronizationAlgorithm (org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm)1 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)1 TmfTestTrace (org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace)1 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)1 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)1 TmfExperimentStub (org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub)1 TmfXmlTraceStubNs (org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs)1