Search in sources :

Example 1 with ObjectStore

use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.

the class IdempotentRedeliveryPolicyTestCase method testMessageRedeliveryUsingSerializationStore.

@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));
}
Also used : TemplateObjectStore(org.mule.runtime.api.store.TemplateObjectStore) ObjectStore(org.mule.runtime.api.store.ObjectStore) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 2 with ObjectStore

use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.

the class MuleObjectStoreManagerIntegrationTestCase method storeUsingBigKey.

@Test
public void storeUsingBigKey() throws Exception {
    ObjectStore os = objectStoreFactory.createObjectStore("myOs");
    StringBuilder bigKey = new StringBuilder();
    for (int i = 0; i < 50; i++) {
        bigKey.append("abcdefghijklmnopqrstuvwxyz");
    }
    os.store(bigKey.toString(), 1);
    assertThat(os.retrieve(bigKey.toString()), Is.is(1));
}
Also used : ObjectStore(org.mule.runtime.api.store.ObjectStore) Test(org.junit.Test)

Example 3 with ObjectStore

use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.

the class MuleObjectStoreManagerIntegrationTestCase method expirationIntervalWithLowTTL.

@Test
public void expirationIntervalWithLowTTL() throws Exception {
    int maxEntries = 5;
    int entryTTL = 10;
    int expirationInterval = 100;
    final ObjectStore os = objectStoreFactory.createObjectStore("myOs", maxEntries, entryTTL, expirationInterval);
    for (int i = 0; i < maxEntries; i++) {
        os.store(valueOf(i), i);
    }
    PollingProber prober = new PollingProber(1000, expirationInterval);
    prober.check(new JUnitProbe() {

        @Override
        public boolean test() throws Exception {
            return os.allKeys().isEmpty();
        }

        @Override
        public String describeFailure() {
            return "not all entries were evicted";
        }
    });
}
Also used : JUnitProbe(org.mule.tck.probe.JUnitProbe) ObjectStore(org.mule.runtime.api.store.ObjectStore) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreNotAvailableException(org.mule.runtime.api.store.ObjectStoreNotAvailableException) Test(org.junit.Test)

Example 4 with ObjectStore

use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.

the class MuleObjectStoreManagerIntegrationTestCase method expirationIntervalWithHighTTLPersistentObjectStore.

@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));
}
Also used : ObjectStore(org.mule.runtime.api.store.ObjectStore) Test(org.junit.Test)

Example 5 with ObjectStore

use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.

the class MuleObjectStoreManagerIntegrationTestCase method partitionObjectStoreDoesNotCollide.

@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));
}
Also used : ObjectStore(org.mule.runtime.api.store.ObjectStore) Test(org.junit.Test)

Aggregations

ObjectStore (org.mule.runtime.api.store.ObjectStore)10 Test (org.junit.Test)8 List (java.util.List)2 Scheduler (org.mule.runtime.api.scheduler.Scheduler)2 ObjectStoreNotAvailableException (org.mule.runtime.api.store.ObjectStoreNotAvailableException)2 PartitionableObjectStore (org.mule.runtime.api.store.PartitionableObjectStore)2 JUnitProbe (org.mule.tck.probe.JUnitProbe)2 PollingProber (org.mule.tck.probe.PollingProber)2 String.format (java.lang.String.format)1 System.currentTimeMillis (java.lang.System.currentTimeMillis)1 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 DAYS (java.util.concurrent.TimeUnit.DAYS)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 Collectors.toList (java.util.stream.Collectors.toList)1