mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 05:55:51 +00:00
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:
parent
a620f52dce
commit
2300f72c52
1 changed files with 23 additions and 0 deletions
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue