diff --git a/core/main/java/com/codingchili/core/configuration/CoreStrings.java b/core/main/java/com/codingchili/core/configuration/CoreStrings.java index cb03a0a2..e1592ac8 100644 --- a/core/main/java/com/codingchili/core/configuration/CoreStrings.java +++ b/core/main/java/com/codingchili/core/configuration/CoreStrings.java @@ -443,7 +443,7 @@ public static String getStorageLoaderMissingArgument(String type) { return "storage loader is missing argument for attribute '" + type + "'."; } - public static String getNothingToReplaceException(String key) { + public static String getNothingToUpdateException(String key) { return "Error: nothing to replace for given key '" + key + "'."; } diff --git a/core/main/java/com/codingchili/core/storage/ElasticMap.java b/core/main/java/com/codingchili/core/storage/ElasticMap.java index 9ef954af..1d2b544c 100644 --- a/core/main/java/com/codingchili/core/storage/ElasticMap.java +++ b/core/main/java/com/codingchili/core/storage/ElasticMap.java @@ -147,11 +147,11 @@ public void update(Value value, Handler> handler) { if (response.getResult().ordinal() != 0) { handler.handle(result()); } else { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } }, exception -> { if (nested(exception) instanceof DocumentMissingException) { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } else { handler.handle(error(exception)); } diff --git a/core/main/java/com/codingchili/core/storage/HazelMap.java b/core/main/java/com/codingchili/core/storage/HazelMap.java index 1803866f..46eeb057 100644 --- a/core/main/java/com/codingchili/core/storage/HazelMap.java +++ b/core/main/java/com/codingchili/core/storage/HazelMap.java @@ -4,7 +4,7 @@ import com.codingchili.core.context.FutureHelper; import com.codingchili.core.context.StorageContext; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import com.hazelcast.core.Hazelcast; @@ -123,7 +123,7 @@ public void update(Value value, Handler> handler) { map.replace(value.id(), value, replace -> { if (replace.succeeded()) { if (replace.result() == null) { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } else { handler.handle(FutureHelper.result()); } diff --git a/core/main/java/com/codingchili/core/storage/IndexedMap.java b/core/main/java/com/codingchili/core/storage/IndexedMap.java index eee1e3e2..e37764f8 100644 --- a/core/main/java/com/codingchili/core/storage/IndexedMap.java +++ b/core/main/java/com/codingchili/core/storage/IndexedMap.java @@ -3,7 +3,7 @@ import com.codingchili.core.context.StorageContext; import com.codingchili.core.protocol.Serializer; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import com.googlecode.cqengine.attribute.Attribute; @@ -121,11 +121,11 @@ public void remove(String key, Handler> handler) { @Override public void update(Value value, Handler> handler) { - remove(value.id(), removed -> { - if (removed.succeeded()) { - put(value, handler); + get(value.id(), get -> { + if (get.succeeded() && db.update(Collections.singleton(get.result()), Collections.singleton(value))) { + handler.handle(succeededFuture()); } else { - handler.handle(failedFuture(new NothingToReplaceException(value.id()))); + handler.handle(failedFuture(new NothingToUpdateException(value.id()))); } }); } diff --git a/core/main/java/com/codingchili/core/storage/JsonMap.java b/core/main/java/com/codingchili/core/storage/JsonMap.java index 87206844..e9a3f05f 100644 --- a/core/main/java/com/codingchili/core/storage/JsonMap.java +++ b/core/main/java/com/codingchili/core/storage/JsonMap.java @@ -6,7 +6,7 @@ import com.codingchili.core.files.exception.NoSuchResourceException; import com.codingchili.core.logging.Logger; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import io.vertx.core.AsyncResult; @@ -135,7 +135,7 @@ public void update(Value value, Handler> handler) { put(value); handler.handle(FutureHelper.result()); } else { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } } diff --git a/core/main/java/com/codingchili/core/storage/MongoDBMap.java b/core/main/java/com/codingchili/core/storage/MongoDBMap.java index 818a9a8d..e3af35ca 100644 --- a/core/main/java/com/codingchili/core/storage/MongoDBMap.java +++ b/core/main/java/com/codingchili/core/storage/MongoDBMap.java @@ -5,7 +5,7 @@ import com.codingchili.core.protocol.Serializer; import com.codingchili.core.security.Validator; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import io.vertx.core.AsyncResult; @@ -134,7 +134,7 @@ public void update(Value value, Handler> handler) { if (replace.result().getDocModified() > 0) { handler.handle(FutureHelper.result()); } else { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } } else { handler.handle(error(replace.cause())); diff --git a/core/main/java/com/codingchili/core/storage/PrivateMap.java b/core/main/java/com/codingchili/core/storage/PrivateMap.java index c4f3aa36..ee3aa79d 100644 --- a/core/main/java/com/codingchili/core/storage/PrivateMap.java +++ b/core/main/java/com/codingchili/core/storage/PrivateMap.java @@ -3,7 +3,7 @@ import com.codingchili.core.context.FutureHelper; import com.codingchili.core.context.StorageContext; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import io.vertx.core.AsyncResult; @@ -91,7 +91,7 @@ public void update(Value value, Handler> handler) { map.put(value.id(), value); handler.handle(FutureHelper.result()); } else { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } } diff --git a/core/main/java/com/codingchili/core/storage/SharedMap.java b/core/main/java/com/codingchili/core/storage/SharedMap.java index bbc795f6..013c71ea 100644 --- a/core/main/java/com/codingchili/core/storage/SharedMap.java +++ b/core/main/java/com/codingchili/core/storage/SharedMap.java @@ -3,7 +3,7 @@ import com.codingchili.core.context.FutureHelper; import com.codingchili.core.context.StorageContext; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import io.vertx.core.AsyncResult; @@ -82,7 +82,7 @@ public void update(Value value, Handler> handler) { if (map.replace(value.id(), value) != null) { handler.handle(FutureHelper.result()); } else { - handler.handle(error(new NothingToReplaceException(value.id()))); + handler.handle(error(new NothingToUpdateException(value.id()))); } } diff --git a/core/main/java/com/codingchili/core/storage/exception/NothingToReplaceException.java b/core/main/java/com/codingchili/core/storage/exception/NothingToUpdateException.java similarity index 53% rename from core/main/java/com/codingchili/core/storage/exception/NothingToReplaceException.java rename to core/main/java/com/codingchili/core/storage/exception/NothingToUpdateException.java index bd0fbcde..a7edb250 100644 --- a/core/main/java/com/codingchili/core/storage/exception/NothingToReplaceException.java +++ b/core/main/java/com/codingchili/core/storage/exception/NothingToUpdateException.java @@ -7,11 +7,12 @@ /** * @author Robin Duda *

- * Throw when the replace operation cannot complete as there is nothing to replace. + * Throw when the replace operation cannot complete as there is no object stored + * that matches the value of the oject to update. */ -public class NothingToReplaceException extends CoreException { +public class NothingToUpdateException extends CoreException { - public NothingToReplaceException(Object key) { - super(CoreStrings.getNothingToReplaceException(key.toString()), ResponseStatus.MISSING); + public NothingToUpdateException(String key) { + super(CoreStrings.getNothingToUpdateException(key), ResponseStatus.MISSING); } } diff --git a/core/main/java/com/codingchili/core/testing/MapTestCases.java b/core/main/java/com/codingchili/core/testing/MapTestCases.java index 8dc56259..c2ed1653 100644 --- a/core/main/java/com/codingchili/core/testing/MapTestCases.java +++ b/core/main/java/com/codingchili/core/testing/MapTestCases.java @@ -10,7 +10,7 @@ import com.codingchili.core.storage.SortOrder; import com.codingchili.core.storage.StorageLoader; import com.codingchili.core.storage.exception.NothingToRemoveException; -import com.codingchili.core.storage.exception.NothingToReplaceException; +import com.codingchili.core.storage.exception.NothingToUpdateException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; import com.codingchili.core.storage.exception.ValueMissingException; import io.vertx.core.AsyncResult; @@ -237,30 +237,30 @@ public void testRemoveNotPresent(TestContext test) { } @Test - public void testReplace(TestContext test) { + public void testUpdate(TestContext test) { Async async = test.async(); int level = 50; - StorageObject replacement = new StorageObject(OBJECT_TWO.id(), level); + StorageObject updated = new StorageObject(OBJECT_TWO.id(), level); - store.update(replacement, replace -> { + store.update(updated, replace -> { test.assertTrue(replace.succeeded(), errorText(replace)); store.get(TWO, get -> { test.assertTrue(get.succeeded(), errorText(get)); - test.assertEquals(replacement.getLevel(), get.result().getLevel()); + test.assertEquals(updated.getLevel(), get.result().getLevel()); async.complete(); }); }); } @Test - public void testReplaceIfNotPresent(TestContext test) { + public void testUpdateIfNotePresent(TestContext test) { Async async = test.async(); StorageObject object = new StorageObject(NAME_MISSING, 0); store.update(object, replace -> { test.assertTrue(replace.failed()); - test.assertEquals(NothingToReplaceException.class, replace.cause().getClass()); + test.assertEquals(NothingToUpdateException.class, replace.cause().getClass()); async.complete(); }); }