Adds Shadow Write Test Method

Commit adds the test method for the shadow write. It ensures that any inconsistencies are properly handled and that changes to the old database are properly mirrored in the new database.
This commit is contained in:
Zackkogan 2018-04-02 23:20:21 -04:00
parent a620f52dce
commit 2300f72c52

View file

@ -8,12 +8,16 @@ import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.samples.petclinic.owner.Owner;
import org.springframework.samples.petclinic.owner.OwnerRepository; import org.springframework.samples.petclinic.owner.OwnerRepository;
import org.springframework.samples.petclinic.owner.StaticOwner; import org.springframework.samples.petclinic.owner.StaticOwner;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
/** /**
* @author Gibran * @author Gibran
*/ */
@ -28,6 +32,9 @@ public class NewOwnerStoreTest {
Map<Integer, StaticOwner> ownerStore; Map<Integer, StaticOwner> ownerStore;
@Mock
Owner mockOwner;
@Before @Before
public void setup() { public void setup() {
testOwnerStore = new NewOwnerStore(owner); testOwnerStore = new NewOwnerStore(owner);
@ -50,4 +57,20 @@ public class NewOwnerStoreTest {
public void consistencyCheck () { public void consistencyCheck () {
System.out.println(testOwnerStore.checkConsistency()); System.out.println(testOwnerStore.checkConsistency());
} }
@Test
public void checkShadowWrite() {
testOwnerStore = new NewOwnerStore(owner);
//make sure that inconsisties are recorded and fixed
testOwnerStore.testPutInOldDatastoreOnly(mockOwner);
assertEquals(1, testOwnerStore.checkConsistency());
assertEquals(0, testOwnerStore.checkConsistency());
//make sure that any changes written to old database are also written to new database
testOwnerStore.save(mockOwner);
assertEquals(0, testOwnerStore.checkConsistency());
}
} }