public void storeMoney(ObjectStore<Long> objectStore, Long money) throws Exception { objectStore.store("money", money); }
private static <T extends Exception> ObjectStore<T> getObjectStore(MuleContext muleContext) { return muleContext.getObjectStoreManager().createObjectStore("SerializationTestUtils", ObjectStoreSettings.builder().persistent(true).build()); }
@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; } }
public <T extends ObjectStore<? extends Serializable>> T createObjectStore( String name, int maxEntries, long entryTTL, long expirationInterval) throws ObjectStoreNotAvailableException { return (T) muleObjectStoreManager.createObjectStore(name, ObjectStoreSettings.builder() .persistent(isPersistent) .maxEntries(maxEntries) .entryTtl(entryTTL) .expirationInterval(expirationInterval) .build()); } }
@Test public void testInMemoryStore() throws ObjectStoreException, InterruptedException, RegistrationException { getRegistry().registerObject(BASE_IN_MEMORY_OBJECT_STORE_KEY, new SimpleMemoryObjectStore<String>()); ObjectStoreManager manager = getRegistry().lookupObject(OBJECT_STORE_MANAGER); ObjectStore<String> store = manager.createObjectStore("inMemoryPart1", unmanagedTransient()); testObjectStore(store); testObjectStoreExpiry(manager, "inMemoryExpPart1", ObjectStoreSettings.builder() .persistent(false) .entryTtl(500L) .expirationInterval(200L) .build()); testObjectStoreMaxEntries(manager, "inMemoryMaxPart1", ObjectStoreSettings.builder() .persistent(false) .maxEntries(10) .entryTtl(10000L) .expirationInterval(200L) .build()); }
@Test public void serialization() throws Exception { final String key = "key"; ObjectStore<DateTime> os = muleContext.getObjectStoreManager().createObjectStore("DateTimeTestCase", unmanagedPersistent()); try { os.store(key, now); DateTime recovered = os.retrieve(key); assertEquals(now, recovered); } finally { os.clear(); } }
@Test public void testClearPartition() throws ObjectStoreException, InterruptedException, RegistrationException { getRegistry().registerObject(BASE_IN_MEMORY_OBJECT_STORE_KEY, new SimpleMemoryObjectStore<String>()); ObjectStoreManager manager = getRegistry().lookupObject(OBJECT_STORE_MANAGER); ObjectStore<String> partition1 = manager.createObjectStore("inMemoryPart1", unmanagedTransient()); ObjectStore<String> partition2 = manager.createObjectStore("inMemoryPart2", unmanagedTransient()); partition1.store("key1", "value1"); partition2.store("key2", "value2"); assertEquals("value1", partition1.retrieve("key1")); assertEquals("value2", partition2.retrieve("key2")); partition1.clear(); assertEquals("value2", partition2.retrieve("key2")); }
public <T extends ObjectStore<? extends Serializable>> T createObjectStore(String name) throws ObjectStoreNotAvailableException { return (T) muleObjectStoreManager.createObjectStore(name, ObjectStoreSettings.builder().persistent(isPersistent).build()); }
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 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); }
@After public void tearDown() throws Exception { try { getMetadataObjectStore().clear(); } catch (Exception ignored) { } }
@Override public boolean test() throws Exception { return os.allKeys().isEmpty(); }
private ObjectStore<MetadataCache> getMetadataObjectStore() { return objectStoreManager.getObjectStore(PERSISTENT_METADATA_SERVICE_CACHE); }
@Override public boolean isSatisfied() { try { return !memoryObjectStore.contains(TEST_GROUP_ID, "prefix.eventGroups"); } catch (ObjectStoreException e) { LOGGER.debug("Could not access object store."); return false; } }
@Override public ObjectStore<Serializable> getObjectStore() { return new SimpleMemoryObjectStore<>(); }
private ObjectStorePartition<Serializable> createStorePartition(String partitionName, boolean isPersistent) throws InitialisationException { addJavaSerializerToMockMuleContext(muleContext); storeManager.initialise(); ObjectStorePartition<Serializable> store = storeManager.createObjectStore(partitionName, ObjectStoreSettings.builder() .persistent(isPersistent) .entryTtl(10000L) .expirationInterval(50L) .build()); assertThat(storeManager.getObjectStore(partitionName), is(sameInstance(store))); return store; }
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); } }
@Before public void setUp() throws Exception { try { getMetadataObjectStore().clear(); } catch (Exception ignored) { } }
private Supplier<ObjectStore> getObjectStoreSupplier(OAuthConfig config) { return () -> { String storeName = config.getStoreConfig() .map(OAuthObjectStoreConfig::getObjectStoreName) .orElse(BASE_PERSISTENT_OBJECT_STORE_KEY); return objectStoreManager.getObjectStore(storeName); }; }