Search in sources :

Example 16 with VectorClock

use of org.syncany.database.VectorClock in project syncany by syncany.

the class VectorClockTest method testCompareSmallerClocksWithDifferentUnitCount.

@Test
public void testCompareSmallerClocksWithDifferentUnitCount() {
    VectorClock vc1 = new VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
    VectorClock vc2 = new VectorClock();
    // same
    vc2.setClock("UnitA", 4L);
    // same
    vc2.setClock("UnitB", 5L);
    // not in vc1
    vc2.setClock("UnitC", 100000L);
    assertEquals("Expected clock 1 to be smaller than clock 2.", VectorClockComparison.SMALLER, VectorClock.compare(vc1, vc2));
    assertEquals("Expected clock 2 to be greater than clock 1.", VectorClockComparison.GREATER, VectorClock.compare(vc2, vc1));
}
Also used : VectorClock(org.syncany.database.VectorClock) Test(org.junit.Test)

Example 17 with VectorClock

use of org.syncany.database.VectorClock in project syncany by syncany.

the class VectorClockTest method testNormalVectorClockUsage.

@Test
public void testNormalVectorClockUsage() {
    VectorClock vc = new VectorClock();
    vc.setClock("UnitA", 1);
    vc.setClock("UnitB", 2);
    vc.setClock("UnitC", 3);
    assertEquals("Expected clock value to be different.", 1L, (long) vc.getClock("UnitA"));
    assertEquals("Expected clock value to be different.", 2L, (long) vc.getClock("UnitB"));
    assertEquals("Expected clock value to be different.", 3L, (long) vc.getClock("UnitC"));
}
Also used : VectorClock(org.syncany.database.VectorClock) Test(org.junit.Test)

Example 18 with VectorClock

use of org.syncany.database.VectorClock in project syncany by syncany.

the class VectorClockTest method testParseClock.

@Test
public void testParseClock() {
    VectorClock vc1 = VectorClock.parseVectorClock("(UnitBBB5,UnitAAA4)");
    assertEquals(4L, (long) vc1.get("UnitAAA"));
    assertEquals(5L, (long) vc1.get("UnitBBB"));
}
Also used : VectorClock(org.syncany.database.VectorClock) Test(org.junit.Test)

Example 19 with VectorClock

use of org.syncany.database.VectorClock in project syncany by syncany.

the class VectorClockTest method testCompareGreaterClocksWithSameUnitCount.

@Test
public void testCompareGreaterClocksWithSameUnitCount() {
    VectorClock vc1 = new VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
    VectorClock vc2 = new VectorClock();
    vc2.setClock("UnitA", 4L);
    // greater!
    vc2.setClock("UnitB", 100000L);
    assertEquals("Expected clock 2 to be greater than clock 1.", VectorClockComparison.GREATER, VectorClock.compare(vc2, vc1));
    assertEquals("Expected clock 1 to be smaller than clock 2.", VectorClockComparison.SMALLER, VectorClock.compare(vc1, vc2));
}
Also used : VectorClock(org.syncany.database.VectorClock) Test(org.junit.Test)

Example 20 with VectorClock

use of org.syncany.database.VectorClock in project syncany by syncany.

the class VectorClockTest method testIncrementNonExistingUnit.

@Test
public void testIncrementNonExistingUnit() {
    VectorClock vc = new VectorClock();
    vc.incrementClock("NonExistingUnit");
    assertEquals("Expected clock value to be different.", 1L, (long) vc.getClock("NonExistingUnit"));
}
Also used : VectorClock(org.syncany.database.VectorClock) Test(org.junit.Test)

Aggregations

VectorClock (org.syncany.database.VectorClock)28 Test (org.junit.Test)14 IOException (java.io.IOException)5 Date (java.util.Date)5 DatabaseVersion (org.syncany.database.DatabaseVersion)5 DatabaseVersionHeader (org.syncany.database.DatabaseVersionHeader)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 MemoryDatabase (org.syncany.database.MemoryDatabase)3 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 PartialFileHistory (org.syncany.database.PartialFileHistory)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 ChunkEntry (org.syncany.database.ChunkEntry)1