use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.
the class MuleObjectStoreManagerIntegrationTestCase method maxEntriesIsHonored.
@Test
public void maxEntriesIsHonored() throws Exception {
final int expirationInterval = 1000;
final int maxEntries = 5;
final ObjectStore os = objectStoreFactory.createObjectStore("myOs", 5, 0, expirationInterval);
os.store("0", 0);
ensureMilisecondChanged();
for (int i = 1; i < maxEntries + 1; i++) {
os.store(valueOf(i), i);
}
PollingProber prober = new PollingProber(expirationInterval * 5, expirationInterval);
prober.check(new JUnitProbe() {
@Override
public boolean test() throws Exception {
assertThat(os.contains("0"), is(false));
for (int i = 1; i < maxEntries + 1; i++) {
assertThat(os.contains(valueOf(i)), is(true));
}
return true;
}
@Override
public String describeFailure() {
return "max entries were not honoured";
}
});
}
use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.
the class MuleObjectStoreManagerIntegrationTestCase method onlySizeBoundedObjectStore.
@Test
public void onlySizeBoundedObjectStore() throws Exception {
final int maxEntries = 5;
final int entryTTL = UNBOUNDED;
final ObjectStore os = objectStoreFactory.createObjectStore("myOs", maxEntries, entryTTL, 1000);
os.store("0", 0);
ensureMilisecondChanged();
for (int i = 1; i < maxEntries + 1; i++) {
os.store(valueOf(i), i);
}
PollingProber prober = new PollingProber(5000, 1000);
prober.check(new JUnitProbe() {
@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;
}
@Override
public String describeFailure() {
return "objectStore was not trimmed";
}
});
}
use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.
the class EventCorrelator method handleGroupExpiry.
protected void handleGroupExpiry(EventGroup group) throws MuleException {
try {
removeEventGroup(group);
} catch (ObjectStoreException e) {
throw new DefaultMuleException(e);
}
if (isFailOnTimeout()) {
CoreEvent messageCollectionEvent = group.getMessageCollectionEvent();
notificationFirer.dispatch(new RoutingNotification(messageCollectionEvent.getMessage(), null, CORRELATION_TIMEOUT));
try {
group.clear();
} catch (ObjectStoreException e) {
logger.warn("Failed to clear group with id " + group.getGroupId() + " since underlying ObjectStore threw Exception:" + e.getMessage());
}
throw new CorrelationTimeoutException(correlationTimedOut(group.getGroupId()));
} else {
if (logger.isDebugEnabled()) {
logger.debug(MessageFormat.format("Aggregator expired, but ''failOnTimeOut'' is false. Forwarding {0} events out of {1} " + "total for group ID: {2}", group.size(), group.expectedSize().map(v -> v.toString()).orElse(NOT_SET), group.getGroupId()));
}
try {
if (!(group.getCreated() + DAYS.toMillis(1) < currentTimeMillis())) {
CoreEvent newEvent = CoreEvent.builder(callback.aggregateEvents(group)).build();
group.clear();
if (!correlatorStore.contains((String) group.getGroupId(), getExpiredAndDispatchedPartitionKey())) {
// returned?
if (timeoutMessageProcessor != null) {
processToApply(newEvent, timeoutMessageProcessor, false, empty());
} else {
throw new MessagingException(createStaticMessage(MessageFormat.format("Group {0} timed out, but no timeout message processor was " + "configured.", group.getGroupId())), newEvent);
}
correlatorStore.store((String) group.getGroupId(), group.getCreated(), getExpiredAndDispatchedPartitionKey());
} else {
logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
}
}
} catch (MessagingException me) {
throw me;
} catch (Exception e) {
throw new MessagingException(group.getMessageCollectionEvent(), e);
}
}
}
use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.
the class MuleObjectStoreManager method disposeStore.
/**
* {@inheritDoc}
*/
@Override
public void disposeStore(String name) throws ObjectStoreException {
if (basePersistentStoreKey.equals(name) || baseTransientStoreKey.equals(name)) {
return;
}
ObjectStore store = stores.remove(name);
if (store == null) {
throw noSuchStoreException(name);
}
try {
if (store instanceof ObjectStorePartition) {
ObjectStorePartition partition = (ObjectStorePartition) store;
String partitionName = partition.getPartitionName();
partition.getBaseStore().disposePartition(partitionName);
Scheduler scheduler = expirationSchedulers.remove(partitionName);
if (scheduler != null) {
scheduler.stop();
}
} else {
try {
store.clear();
} catch (UnsupportedOperationException e) {
LOGGER.warn(format("ObjectStore of class %s does not support clearing", store.getClass().getCanonicalName()), e);
}
}
} finally {
disposeIfNeeded(store, LOGGER);
}
}
use of org.mule.runtime.api.store.ObjectStore in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method objectStoreParameters.
@Test
public void objectStoreParameters() {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
OperationModel operationModel = extensionModel.getOperationModel("storeMoney").get();
ParameterModel parameter = operationModel.getAllParameterModels().stream().filter(p -> "objectStore".equals(p.getName())).findFirst().get();
StereotypeModel stereotype = parameter.getAllowedStereotypes().stream().filter(s -> s.getType().equals(OBJECT_STORE.getType())).findFirst().get();
assertThat(stereotype.getNamespace(), equalTo(OBJECT_STORE.getNamespace()));
Optional<ImportedTypeModel> typeImport = extensionModel.getImportedTypes().stream().filter(i -> getTypeId(i.getImportedType()).map(id -> ObjectStore.class.getName().equals(id)).orElse(false)).findFirst();
assertThat(typeImport.isPresent(), is(true));
}
Aggregations