@Test public void merge_mergingUptodate() { CacheEntry existing = cacheEntryWithVersion(versionOld); CacheEntry merging = cacheEntryWithVersion(versionNew); MergingValue entryExisting = entryWithGivenValue(existing); MergingValue entryMerging = entryWithGivenValue(merging); assertEquals(merging, policy.merge(entryMerging, entryExisting)); }
@Override public Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal) { final Object existingValue = existingVal != null ? existingVal.getValue() : null; final Object mergingValue = mergingVal != null ? mergingVal.getValue() : null; if (existingValue instanceof CacheEntry && mergingValue instanceof CacheEntry) { final CacheEntry existingCacheEntry = (CacheEntry) existingValue; final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue; final Object mergingVersionObject = mergingCacheEntry.getVersion(); final Object existingVersionObject = existingCacheEntry.getVersion(); if (mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) { final Comparable mergingVersion = (Comparable) mergingVersionObject; final Comparable existingVersion = (Comparable) existingVersionObject; if (mergingVersion.compareTo(existingVersion) > 0) { return mergingValue; } else { return existingValue; } } } return mergingValue; }
VersionAwareMapMergePolicy implements SplitBrainMergePolicy<Object, MergingValue<Object>, Object> { @Override public Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal) { final Object existingValue = existingVal != null ? existingVal.getValue() : null; final Object mergingValue = mergingVal != null ? mergingVal.getValue() : null; if (existingValue instanceof CacheEntry && mergingValue instanceof CacheEntry) { final CacheEntry existingCacheEntry = (CacheEntry) existingValue; final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue; final Object mergingVersionObject = mergingCacheEntry.getVersion(); final Object existingVersionObject = existingCacheEntry.getVersion(); if (mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) { final Comparable mergingVersion = (Comparable) mergingVersionObject; final Comparable existingVersion = (Comparable) existingVersionObject; if (mergingVersion.compareTo(existingVersion) > 0) { return mergingValue; } else { return existingValue; } } } return mergingValue; } }
VersionAwareMapMergePolicy implements SplitBrainMergePolicy<Object, MergingValue<Object>, Object> { @Override public Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal) { final Object existingValue = existingVal != null ? existingVal.getValue() : null; final Object mergingValue = mergingVal != null ? mergingVal.getValue() : null; if (existingValue instanceof CacheEntry && mergingValue instanceof CacheEntry) { final CacheEntry existingCacheEntry = (CacheEntry) existingValue; final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue; final Object mergingVersionObject = mergingCacheEntry.getVersion(); final Object existingVersionObject = existingCacheEntry.getVersion(); if (mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) { final Comparable mergingVersion = (Comparable) mergingVersionObject; final Comparable existingVersion = (Comparable) existingVersionObject; if (mergingVersion.compareTo(existingVersion) > 0) { return mergingValue; } else { return existingValue; } } } return mergingValue; }  }
VersionAwareMapMergePolicy implements SplitBrainMergePolicy<Object, MergingValue<Object>, Object> { @Override public Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal) { final Object existingValue = existingVal != null ? existingVal.getValue() : null; final Object mergingValue = mergingVal != null ? mergingVal.getValue() : null; if (existingValue instanceof CacheEntry && mergingValue instanceof CacheEntry) { final CacheEntry existingCacheEntry = (CacheEntry) existingValue; final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue; final Object mergingVersionObject = mergingCacheEntry.getVersion(); final Object existingVersionObject = existingCacheEntry.getVersion(); if (mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) { final Comparable mergingVersion = (Comparable) mergingVersionObject; final Comparable existingVersion = (Comparable) existingVersionObject; if (mergingVersion.compareTo(existingVersion) > 0) { return mergingValue; } else { return existingValue; } } } return mergingValue; }  @Override Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal); @Override void writeData(ObjectDataOutput out); @Override void readData(ObjectDataInput in); }
VersionAwareMapMergePolicy implements SplitBrainMergePolicy<Object, MergingValue<Object>, Object> { @Override public Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal) { final Object existingValue = existingVal != null ? existingVal.getValue() : null; final Object mergingValue = mergingVal != null ? mergingVal.getValue() : null; if (existingValue instanceof CacheEntry && mergingValue instanceof CacheEntry) { final CacheEntry existingCacheEntry = (CacheEntry) existingValue; final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue; final Object mergingVersionObject = mergingCacheEntry.getVersion(); final Object existingVersionObject = existingCacheEntry.getVersion(); if (mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) { final Comparable mergingVersion = (Comparable) mergingVersionObject; final Comparable existingVersion = (Comparable) existingVersionObject; if (mergingVersion.compareTo(existingVersion) > 0) { return mergingValue; } else { return existingValue; } } } return mergingValue; }  @Override Object merge(MergingValue<Object> mergingVal, MergingValue<Object> existingVal); @Override void writeData(ObjectDataOutput out); @Override void readData(ObjectDataInput in);  }