@Test public void disposePartialId() throws ObjectStoreException { final String partialId = "1874947571-1840879217"; when(objectStore.allKeys()).thenReturn(Arrays.asList(SOME_KEY, OTHER_KEY)); when(objectStore.remove(partialId)).thenThrow(new ObjectDoesNotExistException()); cacheManager.dispose(partialId); verify(objectStore).remove(SOME_KEY); verify(objectStore).remove(OTHER_KEY); }
@Test public void testRemoveWithNullKey() { try { getObjectStore().remove(null); fail("remove() called with null key must throw ObjectStoreException"); } catch (ObjectStoreException ose) { // this one was expected } }
@Test public void testRemoveWithUnboundKey() throws ObjectStoreException { try { // nothing was stored in the OS yet so using any key must trigger the // ObjectDoesNotExistException String key = createKey(); getObjectStore().remove(key); fail("remove() with unbound key must throw ObjectDoesNotExistException"); } catch (ObjectDoesNotExistException odnee) { // this one was expected } }
@Test public void updateCache() throws ObjectStoreException { when(objectStore.contains(SOME_KEY)).thenReturn(true); when(objectStore.remove(SOME_KEY)).thenReturn(mockCache); DefaultMetadataCache cache = new DefaultMetadataCache(); cacheManager.updateCache(SOME_KEY, cache); verify(objectStore).contains(SOME_KEY); verify(objectStore).remove(SOME_KEY); verify(objectStore).store(SOME_KEY, cache); verify(objectStore, never()).retrieve(SOME_KEY); }
@Test public void expireWithoutMaxEntries() throws Exception { when(settings.getMaxEntries()).thenReturn(empty()); when(settings.getEntryTTL()).thenReturn(of(1L)); StoredObject value = new StoredObject("", 0L, KEY); when(objectStore.retrieve(KEY)).thenReturn(value); when(objectStore.allKeys()).thenReturn(asList(KEY)); when(objectStore.contains(KEY)).thenReturn(true); when(objectStore.remove(KEY)).thenReturn(value); wrapper = new MonitoredObjectStoreWrapper(objectStore, settings); wrapper.expire(); check(5000, 100, () -> { verify(objectStore).remove(KEY); return true; }); } }
private void updateWatermark(Serializable value, Comparator comparator) { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { Serializable currentValue = watermarkObjectStore.retrieve(WATERMARK_OS_KEY); if (compareWatermarks(currentValue, value, comparator) >= 0) { return; } watermarkObjectStore.remove(WATERMARK_OS_KEY); } updateRecentlyProcessedIds(); watermarkObjectStore.store(WATERMARK_OS_KEY, value); } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to update watermark value for message source at location '%s'. %s", flowName, e.getMessage())), e); } }
@Test public void partitionObjectStoreDoesNotCollide() throws Exception { ObjectStore os = objectStoreFactory.createObjectStore("myOs"); ObjectStore os2 = objectStoreFactory.createObjectStore("myOs2"); os.store(OBJECT_KEY, OBJECT_KEY_VALUE_1); os2.store(OBJECT_KEY, OBJECT_KEY_VALUE_2); assertThat(os.contains(OBJECT_KEY), is(true)); assertThat(os.retrieve(OBJECT_KEY), is(OBJECT_KEY_VALUE_1)); assertThat(os2.contains(OBJECT_KEY), is(true)); assertThat(os2.retrieve(OBJECT_KEY), is(OBJECT_KEY_VALUE_2)); assertThat(os.remove(OBJECT_KEY), is(OBJECT_KEY_VALUE_1)); assertThat(os2.remove(OBJECT_KEY), is(OBJECT_KEY_VALUE_2)); }
@Override public CoreEvent process(CoreEvent event) throws MuleException { ObjectStore<String> myPartition = objectStoreManager.getOrCreateObjectStore("myPartition", ObjectStoreSettings.builder().persistent(true).build()); String key = "value"; if (myPartition.contains(key)) { myPartition.remove(key); } myPartition.store(key, key); return event; } }
@Override protected T doRemove(String key) throws ObjectStoreException { return getWrapped().remove(key); }
private void resetCounter(String messageId) throws ObjectStoreException { store.remove(messageId); store.store(messageId, new RedeliveryCounter()); }
@Override protected T doRemove(String key) throws ObjectStoreException { StoredObject<T> object = getStore().remove(key); if (object == null) { return null; } else { return object.getItem(); } }
@Override protected T doRemove(String key) throws ObjectStoreException { return getStore().remove(partitioned(key)); }
private RedeliveryCounter incrementCounter(String messageId, MessagingException ex) throws ObjectStoreException { RedeliveryCounter counter = findCounter(messageId); if (counter == null) { counter = new RedeliveryCounter(); } else { store.remove(messageId); } counter.counter.incrementAndGet(); counter.errors.add(ex.getEvent().getError().get()); store.store(messageId, counter); return counter; }
@Test public void testRemoveWithNullKey() { try { getObjectStore().remove(null); fail("remove() called with null key must throw ObjectStoreException"); } catch (ObjectStoreException ose) { // this one was expected } }
@Test public void testRemoveWithUnboundKey() throws ObjectStoreException { try { // nothing was stored in the OS yet so using any key must trigger the // ObjectDoesNotExistException String key = createKey(); getObjectStore().remove(key); fail("remove() with unbound key must throw ObjectDoesNotExistException"); } catch (ObjectDoesNotExistException odnee) { // this one was expected } }
private void updateWatermark(Serializable value, Comparator comparator) { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { Serializable currentValue = watermarkObjectStore.retrieve(WATERMARK_OS_KEY); if (compareWatermarks(currentValue, value, comparator) >= 0) { return; } watermarkObjectStore.remove(WATERMARK_OS_KEY); recentlyProcessedIds.clear(); } watermarkObjectStore.store(WATERMARK_OS_KEY, value); } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to update watermark value for message source at location '%s'. %s", flowName, e.getMessage())), e); } }
@Test public void partitionObjectStoreDoesNotCollide() throws Exception { ObjectStore os = objectStoreFactory.createObjectStore("myOs"); ObjectStore os2 = objectStoreFactory.createObjectStore("myOs2"); os.store(OBJECT_KEY, OBJECT_KEY_VALUE_1); os2.store(OBJECT_KEY, OBJECT_KEY_VALUE_2); assertThat(os.contains(OBJECT_KEY), is(true)); assertThat(os.retrieve(OBJECT_KEY), is(OBJECT_KEY_VALUE_1)); assertThat(os2.contains(OBJECT_KEY), is(true)); assertThat(os2.retrieve(OBJECT_KEY), is(OBJECT_KEY_VALUE_2)); assertThat(os.remove(OBJECT_KEY), is(OBJECT_KEY_VALUE_1)); assertThat(os2.remove(OBJECT_KEY), is(OBJECT_KEY_VALUE_2)); }