Search in sources :

Example 1 with ObjectAlreadyExistsException

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));
    }
}
Also used : ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) File(java.io.File) FileUtils.newFile(org.mule.runtime.core.api.util.FileUtils.newFile)

Example 2 with ObjectAlreadyExistsException

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);
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 3 with ObjectAlreadyExistsException

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
    }
}
Also used : Serializable(java.io.Serializable) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) Test(org.junit.Test)

Aggregations

ObjectAlreadyExistsException (org.mule.runtime.api.store.ObjectAlreadyExistsException)3 File (java.io.File)1 Serializable (java.io.Serializable)1 Test (org.junit.Test)1 ObjectDoesNotExistException (org.mule.runtime.api.store.ObjectDoesNotExistException)1 ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)1 FileUtils.newFile (org.mule.runtime.core.api.util.FileUtils.newFile)1