@Test(expected = UnsupportedOperationException.class) public void clusteredStore_removeElement_throw_in_eventual_consistency() { clusteredStore.removeElement(new Element("key", "value"), new DefaultElementValueComparator(cacheConfiguration)); }
@Override public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException { if (isEventual) { throw new UnsupportedOperationException( "CAS operations are not supported in eventual consistency mode, consider using a StronglyConsistentCacheAccessor"); } String pKey = generatePortableKeyFor(element.getKey()); ToolkitReadWriteLock lock = backend.createLockForKey(pKey); lock.writeLock().lock(); try { Element oldElement = getQuiet(element.getKey()); if (comparator.equals(oldElement, element)) { return remove(element.getKey()); } } finally { lock.writeLock().unlock(); } return null; }
ClusteredStore implements TerracottaStore, StoreListener { @Override public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException { if (isEventual) { throw new UnsupportedOperationException( "CAS operations are not supported in eventual consistency mode, consider using a StronglyConsistentCacheAccessor"); } String pKey = generatePortableKeyFor(element.getKey()); ToolkitReadWriteLock lock = backend.createLockForKey(pKey); lock.writeLock().lock(); try { Element oldElement = getQuiet(element.getKey()); if (comparator.equals(oldElement, element)) { return remove(element.getKey()); } } finally { lock.writeLock().unlock(); } return null; } }
ClusteredStore implements TerracottaStore, StoreListener { @Override public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException { if (isEventual) { throw new UnsupportedOperationException( "CAS operations are not supported in eventual consistency mode, consider using a StronglyConsistentCacheAccessor"); } String pKey = generatePortableKeyFor(element.getKey()); ToolkitReadWriteLock lock = backend.createLockForKey(pKey); lock.writeLock().lock(); try { Element oldElement = getQuiet(element.getKey()); if (comparator.equals(oldElement, element)) { return remove(element.getKey()); } } finally { lock.writeLock().unlock(); } return null; } ClusteredStore(ToolkitInstanceFactory toolkitInstanceFactory, Ehcache cache, CacheCluster topology); }
ClusteredStore implements TerracottaStore, StoreListener { @Override public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException { if (isEventual) { throw new UnsupportedOperationException( "CAS operations are not supported in eventual consistency mode, consider using a StronglyConsistentCacheAccessor"); } String pKey = generatePortableKeyFor(element.getKey()); ToolkitReadWriteLock lock = backend.createLockForKey(pKey); lock.writeLock().lock(); try { Element oldElement = getQuiet(element.getKey()); if (comparator.equals(oldElement, element)) { return remove(element.getKey()); } } finally { lock.writeLock().unlock(); } return null; } ClusteredStore(ToolkitInstanceFactory toolkitInstanceFactory, Ehcache cache, CacheCluster topology); String getFullyQualifiedCacheName(); @Override void recalculateSize(Object key); @Override synchronized void addStoreListener(StoreListener listener); @Override synchronized void removeStoreListener(StoreListener listener); @Override void clusterCoherent(final boolean clusterCoherent); @Override boolean put(Element element); @Override boolean putWithWriter(Element element, CacheWriterManager writerManager); @Override void putAll(Collection<Element> elements); @Override Element get(Object key); @Override Element getQuiet(Object key); @Override List getKeys(); @Override Element remove(Object key); @Override void removeAll(Collection<?> keys); @Override Element removeWithWriter(Object key, CacheWriterManager writerManager); @Override void removeAll(); @Override Element putIfAbsent(Element element); @Override Element removeElement(Element element, ElementValueComparator comparator); @Override boolean replace(Element old, Element element, ElementValueComparator comparator); @Override Element replace(Element element); @Override void dispose(); @Override int getSize(); @Override @Statistic(name = "size", tags = "local-heap") int getInMemorySize(); @Override @Statistic(name = "size", tags = "local-offheap") int getOffHeapSize(); @Override int getOnDiskSize(); @Override @Statistic(name = "size", tags = "remote") int getTerracottaClusteredSize(); @Override @Statistic(name = "size-in-bytes", tags = "local-heap") long getInMemorySizeInBytes(); @Override @Statistic(name = "size-in-bytes", tags = "local-offheap") long getOffHeapSizeInBytes(); @Override long getOnDiskSizeInBytes(); @Override boolean hasAbortedSizeOf(); @Override Status getStatus(); @Override boolean containsKey(Object key); @Override boolean containsKeyOnDisk(Object key); @Override boolean containsKeyOffHeap(Object key); @Override boolean containsKeyInMemory(Object key); @Override void expireElements(); @Override void flush(); @Override boolean bufferFull(); @Override Policy getInMemoryEvictionPolicy(); @Override void setInMemoryEvictionPolicy(Policy policy); @Override Object getInternalContext(); @Override boolean isCacheCoherent(); @Override boolean isClusterCoherent(); @Override boolean isNodeCoherent(); @Override void setNodeCoherent(boolean coherent); @Override void waitUntilClusterCoherent(); @Override Object getMBean(); @Override void setAttributeExtractors(Map<String, AttributeExtractor> extractors); @Override Results executeQuery(StoreQuery query); @Override Attribute<T> getSearchAttribute(String attributeName); @Override Map<Object, Element> getAllQuiet(Collection<?> keys); @Override Map<Object, Element> getAll(Collection<?> keys); String generatePortableKeyFor(final Object obj); @Override Element unsafeGet(Object key); @Override Set getLocalKeys(); @Override TransactionalMode getTransactionalMode(); boolean isSearchable(); String getLeader(); @Override WriteBehind createWriteBehind(); @Override synchronized void notifyCacheEventListenersChanged(); }
ClusteredStore implements TerracottaStore, StoreListener { @Override public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException { if (isEventual) { throw new UnsupportedOperationException( "CAS operations are not supported in eventual consistency mode, consider using a StronglyConsistentCacheAccessor"); } String pKey = generatePortableKeyFor(element.getKey()); ToolkitReadWriteLock lock = backend.createLockForKey(pKey); lock.writeLock().lock(); try { Element oldElement = getQuiet(element.getKey()); if (comparator.equals(oldElement, element)) { return remove(element.getKey()); } } finally { lock.writeLock().unlock(); } return null; } ClusteredStore(ToolkitInstanceFactory toolkitInstanceFactory, Ehcache cache, CacheCluster topology); String getFullyQualifiedCacheName(); @Override void recalculateSize(Object key); @Override synchronized void addStoreListener(StoreListener listener); @Override synchronized void removeStoreListener(StoreListener listener); @Override void clusterCoherent(final boolean clusterCoherent); @Override boolean put(Element element); @Override boolean putWithWriter(Element element, CacheWriterManager writerManager); @Override void putAll(Collection<Element> elements); @Override Element get(Object key); @Override Element getQuiet(Object key); @Override List getKeys(); @Override Element remove(Object key); @Override void removeAll(Collection<?> keys); @Override Element removeWithWriter(Object key, CacheWriterManager writerManager); @Override void removeAll(); @Override Element putIfAbsent(Element element); @Override Element removeElement(Element element, ElementValueComparator comparator); @Override boolean replace(Element old, Element element, ElementValueComparator comparator); @Override Element replace(Element element); @Override void dispose(); @Override int getSize(); @Override @Statistic(name = "size", tags = "local-heap") int getInMemorySize(); @Override @Statistic(name = "size", tags = "local-offheap") int getOffHeapSize(); @Override int getOnDiskSize(); @Override @Statistic(name = "size", tags = "remote") int getTerracottaClusteredSize(); @Override @Statistic(name = "size-in-bytes", tags = "local-heap") long getInMemorySizeInBytes(); @Override @Statistic(name = "size-in-bytes", tags = "local-offheap") long getOffHeapSizeInBytes(); @Override long getOnDiskSizeInBytes(); @Override boolean hasAbortedSizeOf(); @Override Status getStatus(); @Override boolean containsKey(Object key); @Override boolean containsKeyOnDisk(Object key); @Override boolean containsKeyOffHeap(Object key); @Override boolean containsKeyInMemory(Object key); @Override void expireElements(); @Override void flush(); @Override boolean bufferFull(); @Override Policy getInMemoryEvictionPolicy(); @Override void setInMemoryEvictionPolicy(Policy policy); @Override Object getInternalContext(); @Override boolean isCacheCoherent(); @Override boolean isClusterCoherent(); @Override boolean isNodeCoherent(); @Override void setNodeCoherent(boolean coherent); @Override void waitUntilClusterCoherent(); @Override Object getMBean(); @Override void setAttributeExtractors(Map<String, AttributeExtractor> extractors); @Override Results executeQuery(StoreQuery query); @Override Attribute<T> getSearchAttribute(String attributeName); @Override Map<Object, Element> getAllQuiet(Collection<?> keys); @Override Map<Object, Element> getAll(Collection<?> keys); String generatePortableKeyFor(final Object obj); @Override Element unsafeGet(Object key); @Override Set getLocalKeys(); @Override TransactionalMode getTransactionalMode(); boolean isSearchable(); String getLeader(); @Override WriteBehind createWriteBehind(); @Override synchronized void notifyCacheEventListenersChanged();  }