Package org.syncany.database

Examples of org.syncany.database.VectorClock


import org.syncany.database.VectorClock.VectorClockComparison;

public class VectorClockTest {
  @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"));
  }
View Full Code Here


    assertEquals("Expected clock value to be different.", 3L, (long) vc.getClock("UnitC"));
  }
   
  @Test
  public void testIncrementUnit() {
    VectorClock vc = new  VectorClock();
   
    vc.setClock("UnitA", 1);   
    vc.incrementClock("UnitA"); // 2
    vc.incrementClock("UnitA"); // 3
   
    vc.setClock("UnitB", 2);
    vc.incrementClock("UnitB"); // 3
   
    assertEquals("Expected clock value to be different.", 3L, (long) vc.getClock("UnitA"));
    assertEquals("Expected clock value to be different.", 3L, (long) vc.getClock("UnitB"));
 
View Full Code Here

    assertEquals("Expected clock value to be different.", 3L, (long) vc.getClock("UnitB"));
 
 
  @Test
  public void testCompareEqualClocks() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitA", 4L); // same
    vc2.setClock("UnitB", 5L); // same
   
    assertEquals("Expected clock 1 and 2 to be equal.", VectorClockComparison.EQUAL, VectorClock.compare(vc1, vc2));
    assertEquals("Expected clock 2 and 1 to be equal.", VectorClockComparison.EQUAL, VectorClock.compare(vc2, vc1));
  }   
View Full Code Here

    assertEquals("Expected clock 2 and 1 to be equal.", VectorClockComparison.EQUAL, VectorClock.compare(vc2, vc1));
  }   
 
  @Test
  public void testCompareSmallerClocksWithSameUnitCount() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitA", 4L);
    vc2.setClock("UnitB", 100000L); // greater!
   
    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));
 
View Full Code Here

    assertEquals("Expected clock 2 to be greater than clock 1.", VectorClockComparison.GREATER, VectorClock.compare(vc2, vc1));
 
 
  @Test
  public void testCompareSmallerClocksWithDifferentUnitCount() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitA", 4L); // same
    vc2.setClock("UnitB", 5L); // same
    vc2.setClock("UnitC", 100000L); // not in vc1
   
    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));
  }     
View Full Code Here

    assertEquals("Expected clock 2 to be greater than clock 1.", VectorClockComparison.GREATER, VectorClock.compare(vc2, vc1));
  }     
 
  @Test
  public void testCompareGreaterClocksWithSameUnitCount() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitA", 4L);
    vc2.setClock("UnitB", 100000L); // greater!
   
    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));
 
View Full Code Here

    assertEquals("Expected clock 1 to be smaller than clock 2.", VectorClockComparison.SMALLER, VectorClock.compare(vc1, vc2));
 
 
  @Test
  public void testCompareGreaterClocksWithDifferentUnitCount() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitA", 4L); // same
    vc2.setClock("UnitB", 5L); // same
    vc2.setClock("UnitC", 1L); // not in vc1
   
    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));
 
View Full Code Here

    assertEquals("Expected clock 1 to be smaller than clock 2.", VectorClockComparison.SMALLER, VectorClock.compare(vc1, vc2));
 
 
  @Test
  public void testSimultaneousClocks() {
    VectorClock vc1 = new  VectorClock();
    vc1.setClock("UnitA", 4L);
    vc1.setClock("UnitB", 5L);
   
    VectorClock vc2 = new  VectorClock();
    vc2.setClock("UnitC", 1L);
    vc2.setClock("UnitD", 2L);
   
    assertEquals("Expected clock 1 and 2 to be simulataneous.", VectorClockComparison.SIMULTANEOUS, VectorClock.compare(vc1, vc2));
    assertEquals("Expected clock 2 and 1 to be simulataneous.", VectorClockComparison.SIMULTANEOUS, VectorClock.compare(vc2, vc1));
  }   
View Full Code Here

    assertEquals("Expected clock 2 and 1 to be simulataneous.", VectorClockComparison.SIMULTANEOUS, VectorClock.compare(vc2, vc1));
  }   
 
  @Test
  public void testIncrementNonExistingUnit() {
    VectorClock vc = new  VectorClock();
   
    vc.incrementClock("NonExistingUnit");
   
    assertEquals("Expected clock value to be different.", 1L, (long) vc.getClock("NonExistingUnit"));
 
View Full Code Here

    assertEquals("Expected clock value to be different.", 1L, (long) vc.getClock("NonExistingUnit"));
 
 
  @Test
  public void testNonExistingVectorClockUsage() {
    VectorClock vc = new  VectorClock();
   
    assertEquals("Expected clock value to be different.", 0L, (long) vc.getClock("NonExistingUnit"));
 
View Full Code Here

TOP

Related Classes of org.syncany.database.VectorClock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.