cleanup work
This commit is contained in:
@@ -13,42 +13,41 @@ public class CRDTTest {
|
||||
|
||||
@Test
|
||||
public void givenGrowOnlySet_whenTwoReplicasDiverge_thenShouldMergeItWithoutAConflict() {
|
||||
//given
|
||||
// given
|
||||
final LocalCrdtStore crdtStore1 = new LocalCrdtStore();
|
||||
final LocalCrdtStore crdtStore2 = new LocalCrdtStore();
|
||||
crdtStore1.connect(crdtStore2);
|
||||
|
||||
final GSet<String> replica1 = crdtStore1.createGSet("ID_1");
|
||||
final GSet<String> replica2 = crdtStore2.<String>findGSet("ID_1").get();
|
||||
final GSet<String> replica2 = crdtStore2.<String> findGSet("ID_1").get();
|
||||
|
||||
//when
|
||||
// when
|
||||
replica1.add("apple");
|
||||
replica2.add("banana");
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1).contains("apple", "banana");
|
||||
assertThat(replica2).contains("apple", "banana");
|
||||
|
||||
//when
|
||||
// when
|
||||
crdtStore1.disconnect(crdtStore2);
|
||||
|
||||
replica1.add("strawberry");
|
||||
replica2.add("pear");
|
||||
|
||||
|
||||
assertThat(replica1).contains("apple", "banana", "strawberry");
|
||||
assertThat(replica2).contains("apple", "banana", "pear");
|
||||
|
||||
crdtStore1.connect(crdtStore2);
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1).contains("apple", "banana", "strawberry", "pear");
|
||||
assertThat(replica2).contains("apple", "banana", "strawberry", "pear");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIncrementOnlyCounter_whenTwoReplicasDiverge_thenShouldMergeIt() {
|
||||
//given
|
||||
// given
|
||||
final LocalCrdtStore crdtStore1 = new LocalCrdtStore();
|
||||
final LocalCrdtStore crdtStore2 = new LocalCrdtStore();
|
||||
crdtStore1.connect(crdtStore2);
|
||||
@@ -56,21 +55,20 @@ public class CRDTTest {
|
||||
final GCounter replica1 = crdtStore1.createGCounter("ID_1");
|
||||
final GCounter replica2 = crdtStore2.findGCounter("ID_1").get();
|
||||
|
||||
//when
|
||||
// when
|
||||
replica1.increment();
|
||||
replica2.increment(2L);
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1.get()).isEqualTo(3L);
|
||||
assertThat(replica2.get()).isEqualTo(3L);
|
||||
|
||||
//when
|
||||
// when
|
||||
crdtStore1.disconnect(crdtStore2);
|
||||
|
||||
replica1.increment(3L);
|
||||
replica2.increment(5L);
|
||||
|
||||
|
||||
assertThat(replica1.get()).isEqualTo(6L);
|
||||
assertThat(replica2.get()).isEqualTo(8L);
|
||||
|
||||
@@ -91,15 +89,15 @@ public class CRDTTest {
|
||||
final PNCounter replica1 = crdtStore1.createPNCounter("ID_1");
|
||||
final PNCounter replica2 = crdtStore2.findPNCounter("ID_1").get();
|
||||
|
||||
//when
|
||||
// when
|
||||
replica1.increment();
|
||||
replica2.decrement(2L);
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1.get()).isEqualTo(-1L);
|
||||
assertThat(replica2.get()).isEqualTo(-1L);
|
||||
|
||||
//when
|
||||
// when
|
||||
crdtStore1.disconnect(crdtStore2);
|
||||
|
||||
replica1.decrement(3L);
|
||||
@@ -110,22 +108,22 @@ public class CRDTTest {
|
||||
|
||||
crdtStore1.connect(crdtStore2);
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1.get()).isEqualTo(1L);
|
||||
assertThat(replica2.get()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLastWriteWinsStrategy_whenReplicasDiverge_thenAfterMergeShouldKeepOnlyLastValue() {
|
||||
//given
|
||||
// given
|
||||
final LocalCrdtStore crdtStore1 = new LocalCrdtStore("N_1");
|
||||
final LocalCrdtStore crdtStore2 = new LocalCrdtStore("N_2");
|
||||
crdtStore1.connect(crdtStore2);
|
||||
|
||||
final LWWRegister<String> replica1 = crdtStore1.createLWWRegister("ID_1");
|
||||
final LWWRegister<String> replica2 = crdtStore2.<String>findLWWRegister("ID_1").get();
|
||||
final LWWRegister<String> replica2 = crdtStore2.<String> findLWWRegister("ID_1").get();
|
||||
|
||||
//when
|
||||
// when
|
||||
replica1.set("apple");
|
||||
replica2.set("banana");
|
||||
|
||||
@@ -133,20 +131,18 @@ public class CRDTTest {
|
||||
assertThat(replica1.get()).isEqualTo("banana");
|
||||
assertThat(replica2.get()).isEqualTo("banana");
|
||||
|
||||
|
||||
// when
|
||||
crdtStore1.disconnect(crdtStore2);
|
||||
|
||||
replica1.set("strawberry");
|
||||
replica2.set("pear");
|
||||
|
||||
|
||||
assertThat(replica1.get()).isEqualTo("strawberry");
|
||||
assertThat(replica2.get()).isEqualTo("pear");
|
||||
|
||||
crdtStore1.connect(crdtStore2);
|
||||
|
||||
//then
|
||||
// then
|
||||
assertThat(replica1.get()).isEqualTo("pear");
|
||||
assertThat(replica2.get()).isEqualTo("pear");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user