DatabaseVersionHeaderComparator implements Comparator<DatabaseVersionHeader> { @Override public int compare(DatabaseVersionHeader dbvh1, DatabaseVersionHeader dbvh2) { return compareByVectorClock(dbvh1, dbvh2); } DatabaseVersionHeaderComparator(boolean considerTime); @Override int compare(DatabaseVersionHeader dbvh1, DatabaseVersionHeader dbvh2);  }
@Test public void testCompareDatabaseVersionHeaderEqual() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(true); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(0)); }
@Test public void testCompareDatabaseVersionHeaderEqualIgnoreTime() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(false); dbvh2.setDate(new Date(0xFEBEBEBE)); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(0)); }
@Test public void testCompareDatabaseVersionHeaderSimultaneous() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(true); vc1.setClock("A", 3); vc1.setClock("B", 7); vc2.setClock("A", 5); vc2.setClock("B", 4); dbvh2.setDate(new Date(0xFEBEBEBE)); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(-1)); }
@Test public void testCompareDatabaseVersionHeaderSimultaneousIgnoreTime() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(false); vc1.setClock("A", 3); vc1.setClock("B", 7); vc2.setClock("A", 5); vc2.setClock("B", 4); dbvh2.setDate(new Date(0xFEBEBEBE)); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(0)); }
@Test public void testCompareDatabaseVersionHeaderLarger() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(false); vc1.setClock("A", 3); vc1.setClock("B", 7); vc2.setClock("A", 1); vc2.setClock("B", 7); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(1)); }
@Test public void testCompareDatabaseVersionHeaderSmaller() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(false); vc1.setClock("A", 3); vc1.setClock("B", 7); vc2.setClock("A", 5); vc2.setClock("B", 7); dbvh2.setDate(new Date(0xFEBEBEBE)); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(-1)); }
@Test public void testCompareDatabaseVersionHeaderDifferentClients() { DatabaseVersionHeaderComparator databaseVersionHeaderComparator = new DatabaseVersionHeaderComparator(true); dbvh2.setClient("B"); assertThat(databaseVersionHeaderComparator.compare(dbvh1, dbvh2), is(-1)); }