@Test public void clear() throws ObjectStoreException { String key = this.createKey(); Serializable value = this.getStorableValue(); ObjectStore<Serializable> objectStore = this.getObjectStore(); objectStore.store(key, value); Assert.assertTrue(objectStore.contains(key)); objectStore.clear(); Assert.assertFalse(objectStore.contains(key)); // check it's still usable objectStore.store(key, value); Assert.assertTrue(objectStore.contains(key)); }
if (inflightIdsObjectStore.contains(id)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Source at flow '{}' polled item '{}', but skipping it since it is already being processed in another "
@Test public void testContainsWithNullKey() { try { getObjectStore().contains(null); fail("contains() called with null key must throw ObjectStoreException"); } catch (ObjectStoreException ose) { // this one was expected } }
@Test public void createCacheWhenMissingKey() throws ObjectStoreException { when(objectStore.contains(SOME_KEY)).thenReturn(false); MetadataCache cache = cacheManager.getOrCreateCache(SOME_KEY); assertThat(cache, instanceOf(DefaultMetadataCache.class)); verify(objectStore).contains(SOME_KEY); verify(objectStore, never()).retrieve(SOME_KEY); verify(objectStore).store(SOME_KEY, cache); }
private Serializable getCurrentWatermark() { try { if (watermarkObjectStore.contains(WATERMARK_OS_KEY)) { return watermarkObjectStore.retrieve(WATERMARK_OS_KEY); } else { return null; } } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to fetch watermark for Message source at location '%s'. %s", flowName, e.getMessage())), e); } }
private Serializable getUpdatedWatermark() { try { if (watermarkObjectStore.contains(UPDATED_WATERMARK_OS_KEY)) { return watermarkObjectStore.retrieve(UPDATED_WATERMARK_OS_KEY); } else { return null; } } catch (ObjectStoreException e) { throw new MuleRuntimeException( createStaticMessage(format("Failed to fetch watermark for Message source at location '%s'. %s", flowName, e.getMessage())), e); } }
@Test public void retrieveCacheWhenExists() throws ObjectStoreException { when(objectStore.contains(SOME_KEY)).thenReturn(true); when(objectStore.retrieve(SOME_KEY)).thenReturn(mockCache); MetadataCache actual = cacheManager.getOrCreateCache(SOME_KEY); assertThat(actual, is(mockCache)); verify(objectStore).contains(SOME_KEY); verify(objectStore).retrieve(SOME_KEY); verify(objectStore, never()).store(anyString(), any(MetadataCache.class)); }
@Override public boolean test() throws Exception { assertThat(os.allKeys().size(), is(maxEntries)); for (int i = 1; i < maxEntries + 1; i++) { assertThat(os.contains(valueOf(i)), is(true)); } return true; }
@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 disposeExactId() throws ObjectStoreException { when(objectStore.remove(SOME_KEY)).thenReturn(mockCache); cacheManager.dispose(SOME_KEY); verify(objectStore).remove(SOME_KEY); verify(objectStore, never()).contains(SOME_KEY); 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 expirationIntervalWithHighTTLPersistentObjectStore() throws Exception { int maxEntries = 5; int entryTTL = 10000; ObjectStore os = objectStoreFactory.createObjectStore("myOs", maxEntries, entryTTL, 100); os.store("0", 0); ensureMilisecondChanged(); for (int i = 1; i < maxEntries; i++) { os.store(valueOf(i), i); } os.store(OBJECT_KEY, OBJECT_KEY_VALUE_1); Thread.sleep(entryTTL / 5); assertThat(os.allKeys().size(), is(maxEntries)); for (int i = 1; i < maxEntries; i++) { assertThat(os.contains(valueOf(i)), is(true)); } assertThat(os.contains(OBJECT_KEY), is(true)); }
@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; } }
private void testObjectStoreExpiry(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException { ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings); try { objectStore.store("key1", "value1"); assertEquals("value1", objectStore.retrieve("key1")); new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> { try { assertFalse("Object with key1 still exists.", objectStore.contains("key1")); } catch (Exception e) { fail(e.getMessage()); } return true; })); } finally { manager.disposeStore(storeName); } }
private void testObjectStoreMaxEntries(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException { ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings); try { storeObjects(objectStore, 0, 90); ensureMillisecondChanged(); storeObjects(objectStore, 90, 100); new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> { try { assertEquals(10, objectStore.allKeys().size()); for (int i = 90; i < 100; i++) { assertTrue("Checking that key" + i + " exists", objectStore.contains("key" + i)); } } catch (Exception e) { fail(e.getMessage()); } return true; })); } finally { manager.disposeStore(storeName); } }
@Test public void testContainsWithNullKey() { try { getObjectStore().contains(null); fail("contains() called with null key must throw ObjectStoreException"); } catch (ObjectStoreException ose) { // this one was expected } }