use of org.mule.runtime.api.store.ObjectAlreadyExistsException in project mule by mulesoft.
the class PersistentObjectStorePartition method doStore.
@Override
protected void doStore(String key, T value) throws ObjectStoreException {
assureLoaded();
synchronized (realKeyToUUIDIndex) {
if (realKeyToUUIDIndex.containsKey(key)) {
throw new ObjectAlreadyExistsException();
}
File newFile = createFileToStoreObject();
realKeyToUUIDIndex.put(key, newFile.getName());
serialize(newFile, new StoreValue<T>(key, value));
}
}
use of org.mule.runtime.api.store.ObjectAlreadyExistsException in project mule by mulesoft.
the class ManagedStoresTestCase method testObjectStore.
private void testObjectStore(ObjectStore<String> store) throws ObjectStoreException {
ObjectStoreException e = null;
store.store("key1", "value1");
assertEquals("value1", store.retrieve("key1"));
assertTrue(store.contains("key1"));
store.clear();
assertFalse(store.contains("key1"));
store.store("key1", "value1");
try {
store.store("key1", "value1");
} catch (ObjectAlreadyExistsException e1) {
e = e1;
}
assertNotNull(e);
e = null;
assertEquals(1, store.allKeys().size());
assertEquals("key1", store.allKeys().get(0));
assertEquals("value1", store.remove("key1"));
assertFalse(store.contains("key1"));
try {
store.retrieve("key1");
} catch (ObjectDoesNotExistException e1) {
e = e1;
}
assertNotNull(e);
e = null;
try {
store.remove("key1");
} catch (ObjectDoesNotExistException e1) {
e = e1;
}
assertNotNull(e);
}
use of org.mule.runtime.api.store.ObjectAlreadyExistsException in project mule by mulesoft.
the class TemplateObjectStoreContractTestCase method testStoreWithExistingKey.
@Test
public void testStoreWithExistingKey() throws ObjectStoreException {
String key = createKey();
Serializable value = getStorableValue();
ObjectStore<Serializable> objectStore = getObjectStore();
// storing for the first time must work
objectStore.store(key, value);
// storing with the same key again must fail
try {
objectStore.store(key, value);
fail("store() with an existing key must throw ObjectAlreadyExistsException");
} catch (ObjectAlreadyExistsException oaee) {
// this one was expected
}
}
Aggregations