mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-18 21:45:49 +00:00
Merge Conflicts Addressed
This commit is contained in:
commit
2562a955ae
3 changed files with 66 additions and 9 deletions
|
@ -5,6 +5,7 @@ package org.springframework.samples.petclinic.newDataStore;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.springframework.samples.petclinic.owner.Owner;
|
||||
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||
|
@ -17,8 +18,12 @@ public class NewOwnerStore {
|
|||
|
||||
private HashMap<Integer, StaticOwner> ownerStore;
|
||||
private final OwnerRepository owners;
|
||||
|
||||
private static NewOwnerStore storeSingleton;
|
||||
|
||||
private Collection<Owner> ownerRepositoryData;
|
||||
|
||||
|
||||
private NewOwnerStore(OwnerRepository owners) {
|
||||
this.owners = owners;
|
||||
this.ownerStore = new HashMap<>();
|
||||
|
@ -32,7 +37,9 @@ public class NewOwnerStore {
|
|||
return storeSingleton;
|
||||
}
|
||||
|
||||
public void populateStore() {
|
||||
|
||||
|
||||
public void forklift() {
|
||||
Collection<Owner> ownerRepositoryData = this.owners.findAll();
|
||||
for(Owner owner : ownerRepositoryData) {
|
||||
ownerStore.put(owner.getId(), StaticOwner.convertToStaticOwner(owner));
|
||||
|
@ -55,8 +62,45 @@ public class NewOwnerStore {
|
|||
|
||||
// Replace
|
||||
getStore().put(owner.getId(), StaticOwner.convertToStaticOwner(owner));
|
||||
}
|
||||
|
||||
// Report whether inexistent or inconsistent based on exists
|
||||
|
||||
public int checkConsistency() {
|
||||
int inconsistencies = 0;
|
||||
|
||||
ownerRepositoryData = this.owners.findAll();
|
||||
|
||||
Iterator<Owner> iterator = ownerRepositoryData.iterator();
|
||||
|
||||
for (Integer id: ownerStore.keySet()){
|
||||
|
||||
if(iterator.hasNext()) {
|
||||
Owner oldOwner = iterator.next();
|
||||
if(id != oldOwner.getId() || !ownerStore.get(id).equals(oldOwner)) {
|
||||
inconsistencies++;
|
||||
violation(id, StaticOwner.convertToStaticOwner(oldOwner), ownerStore.get(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
return inconsistencies;
|
||||
}
|
||||
|
||||
private void violation(int i, StaticOwner expected, StaticOwner actual)
|
||||
{
|
||||
System.out.println("Consistency Violation! \n” + “i = ” + i + “\n\t expected = " +
|
||||
expected.toString() + "\n\t actual = " + actual.toString());
|
||||
}
|
||||
|
||||
public void save(Owner owner){
|
||||
//actual write to datastore
|
||||
owners.save(owner);
|
||||
//shadow write to new datastore
|
||||
ownerStore.put(owner.getId(), StaticOwner.convertToStaticOwner(owner));
|
||||
}
|
||||
|
||||
//this is for testing to introduce inconsistencies
|
||||
public void testPutInOldDatastoreOnly(Owner owner){
|
||||
owners.save(owner);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,6 @@ public class StaticOwner {
|
|||
return telephone;
|
||||
}
|
||||
|
||||
|
||||
public static StaticOwner convertToStaticOwner(Owner owner) {
|
||||
return new StaticOwner(owner.getId(), owner.getLastName(), owner.getFirstName(),
|
||||
owner.getAddress(), owner.getCity(), owner.getTelephone());
|
||||
|
|
|
@ -3,9 +3,14 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.newDataStore;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -29,12 +34,18 @@ public class NewOwnerStoreTest {
|
|||
|
||||
NewOwnerStore testOwnerStore;
|
||||
|
||||
@Test
|
||||
public void testPopulation() {
|
||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
||||
testOwnerStore.populateStore();
|
||||
Map<Integer, StaticOwner> ownerStore = testOwnerStore.getStore();
|
||||
HashMap<Integer, StaticOwner> ownerStore;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
||||
testOwnerStore.forklift();
|
||||
ownerStore = testOwnerStore.getStore();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForklift() {
|
||||
for (Integer id: ownerStore.keySet()){
|
||||
|
||||
Integer key = id;
|
||||
|
@ -46,7 +57,7 @@ public class NewOwnerStoreTest {
|
|||
@Test
|
||||
public void testShadowRead() {
|
||||
testOwnerStore = NewOwnerStore.getInstance(owners);
|
||||
testOwnerStore.populateStore();
|
||||
testOwnerStore.forklift();
|
||||
|
||||
Collection<Owner> results = this.owners.findByLastName("");
|
||||
|
||||
|
@ -95,5 +106,8 @@ public class NewOwnerStoreTest {
|
|||
return inconsistencies;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void consistencyCheck () {
|
||||
System.out.println(testOwnerStore.checkConsistency());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue