private static <T extends Exception> ObjectStore<T> getObjectStore(MuleContext muleContext) { return muleContext.getObjectStoreManager().createObjectStore("SerializationTestUtils", ObjectStoreSettings.builder().persistent(true).build()); }
@Test public void testMessageRedeliveryUsingSerializationStore() throws Exception { when(expressionManager.evaluate(eq(format(SECURE_HASH_EXPR_FORMAT, "SHA-256")), eq(STRING), eq(NULL_BINDING_CONTEXT), any())) .thenAnswer(inv -> new TypedValue<>("" + ((CoreEvent) inv.getArgument(3)).getMessage().getPayload().hashCode(), STRING)); when(message.getPayload()).thenReturn(new TypedValue<>(STRING_MESSAGE, STRING)); reset(mockObjectStoreManager); final ObjectStore serializationObjectStore = new SerializationObjectStore(); when(mockObjectStoreManager.createObjectStore(any(), any())).thenReturn(serializationObjectStore); irp.initialise(); processUntilFailure(); assertThat(count.get(), equalTo(MAX_REDELIVERY_COUNT + 1)); }
final InMemoryObjectStore inMemoryObjectStore = new InMemoryObjectStore(); when(mockObjectStoreManager.getObjectStore(anyString())).thenReturn(inMemoryObjectStore); when(mockObjectStoreManager.createObjectStore(any(), any())).thenReturn(inMemoryObjectStore); when(event.getMessage()).thenReturn(message);
@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(); } }
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 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")); }
private Supplier<ObjectStore> internalObjectStoreSupplier() { return () -> { return objectStoreManager.createObjectStore(getLocation().getRootContainerName() + "." + getClass().getName(), ObjectStoreSettings.builder() .persistent(false) .entryTtl((long) 60 * 5 * 1000) .expirationInterval(6000L).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()); }
protected ObjectStore<String> createMessageIdStore() throws InitialisationException { ObjectStoreManager objectStoreManager = ((MuleContextWithRegistries) muleContext).getRegistry().get(OBJECT_STORE_MANAGER); return objectStoreManager.createObjectStore(storePrefix, ObjectStoreSettings.builder() .persistent(false) .entryTtl(MINUTES.toMillis(5)) .expirationInterval(SECONDS.toMillis(6)) .build()); }
private static <T extends Exception> ObjectStore<T> getObjectStore(MuleContext muleContext) { return muleContext.getObjectStoreManager().createObjectStore("SerializationTestUtils", ObjectStoreSettings.builder().persistent(true).build()); }
@Test public void testPartitionableInMemoryStore() throws ObjectStoreException, RegistrationException, InterruptedException { getRegistry().registerObject(BASE_IN_MEMORY_OBJECT_STORE_KEY, new PartitionedInMemoryObjectStore<String>()); ObjectStoreManager manager = getRegistry().lookupObject(OBJECT_STORE_MANAGER); ObjectStore<String> store = manager.createObjectStore("inMemoryPart2", unmanagedTransient()); assertTrue(store instanceof ObjectStorePartition); ObjectStore<String> baseStore = ((ObjectStorePartition<String>) store).getBaseStore(); assertTrue(baseStore instanceof PartitionedInMemoryObjectStore); testObjectStore(store); testObjectStoreExpiry(manager, "inMemoryExpPart2", ObjectStoreSettings.builder() .persistent(false) .entryTtl(500L) .expirationInterval(200L) .build()); testObjectStoreMaxEntries(manager, "inMemoryMaxPart2", ObjectStoreSettings.builder() .persistent(false) .maxEntries(10) .entryTtl(10000L) .expirationInterval(200L) .build()); }
@Test public void testMessageRedeliveryUsingSerializationStore() throws Exception { when(expressionManager.evaluate(eq(format(SECURE_HASH_EXPR_FORMAT, "SHA-256")), eq(STRING), eq(NULL_BINDING_CONTEXT), any())) .thenAnswer(inv -> { return new TypedValue<>("" + inv.getArgumentAt(3, CoreEvent.class).getMessage().getPayload().hashCode(), STRING); }); when(message.getPayload()).thenReturn(new TypedValue<>(STRING_MESSAGE, STRING)); reset(mockObjectStoreManager); final ObjectStore serializationObjectStore = new SerializationObjectStore(); when(mockObjectStoreManager.createObjectStore(any(), any())).thenReturn(serializationObjectStore); irp.initialise(); processUntilFailure(); assertThat(count.get(), equalTo(MAX_REDELIVERY_COUNT + 1)); }
@Ignore("MULE-6926") @Issue("MULE-6926") @Test public void testPartitionablePersistenceStore() throws ObjectStoreException, RegistrationException, InterruptedException { PartitionedPersistentObjectStore<String> partitionedStore = new PartitionedPersistentObjectStore<>(muleContext); partitionedStore.open(); getRegistry().registerObject(BASE_PERSISTENT_OBJECT_STORE_KEY, partitionedStore); ObjectStoreManager manager = getRegistry().lookupObject(OBJECT_STORE_MANAGER); ObjectStore<String> store = manager.createObjectStore("persistencePart2", unmanagedPersistent()); assertTrue(store instanceof ObjectStorePartition); ObjectStore<String> baseStore = ((ObjectStorePartition<String>) store).getBaseStore(); assertTrue(baseStore instanceof PartitionedPersistentObjectStore); assertSame(baseStore, getRegistry().lookupObject(BASE_PERSISTENT_OBJECT_STORE_KEY)); testObjectStore(store); testObjectStoreExpiry(manager, "persistenceExpPart2", ObjectStoreSettings.builder() .persistent(true) .entryTtl(1000L) .expirationInterval(200L) .build()); testObjectStoreMaxEntries(manager, "persistenceMaxPart2", ObjectStoreSettings.builder() .persistent(true) .maxEntries(10) .entryTtl(10000L) .expirationInterval(200L) .build()); }
private Supplier<ObjectStore> internalProcessedGroupsObjectStoreFactory() { return () -> { ObjectStoreManager objectStoreManager = ((MuleContextWithRegistries) muleContext).getRegistry().get(OBJECT_STORE_MANAGER); return objectStoreManager.createObjectStore(storePrefix + ".processedGroups", ObjectStoreSettings.builder() .persistent(persistentStores) .maxEntries(MAX_PROCESSED_GROUPS) .expirationInterval(1000L) .build()); }; }
@Override public void initialise() throws InitialisationException { name = format(NAME_TEMPLATE, storePrefix, muleContext.getConfiguration().getId(), getLocation().getRootContainerName()); MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry(); store = ((ObjectStoreManager) registry.get(OBJECT_STORE_MANAGER)) .createObjectStore(name, ObjectStoreSettings.builder() .persistent(false) .maxEntries(MAX_PROCESSED_GROUPS) .entryTtl(UNCLAIMED_TIME_TO_LIVE) .expirationInterval(UNCLAIMED_INTERVAL) .build()); try { notificationFirer = registry.lookupObject(NotificationDispatcher.class); } catch (RegistrationException e) { throw new InitialisationException(e, this); } }
@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(); } }
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); } }
@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")); }
@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()); }