diff --git a/src/main/java/io/nats/client/impl/NatsKeyValue.java b/src/main/java/io/nats/client/impl/NatsKeyValue.java index f3eaaf452..3c32f1f47 100644 --- a/src/main/java/io/nats/client/impl/NatsKeyValue.java +++ b/src/main/java/io/nats/client/impl/NatsKeyValue.java @@ -155,7 +155,7 @@ public long put(String key, String value) throws IOException, JetStreamApiExcept */ @Override public long put(String key, Number value) throws IOException, JetStreamApiException { - return put(key, value.toString().getBytes(StandardCharsets.US_ASCII)); + return _write(key, value.toString().getBytes(StandardCharsets.US_ASCII), null).getSeqno(); } /** @@ -202,7 +202,6 @@ public long update(String key, String value, long expectedRevision) throws IOExc */ @Override public void delete(String key) throws IOException, JetStreamApiException { - validateNonWildcardKvKeyRequired(key); _write(key, null, getDeleteHeaders()); } @@ -211,9 +210,8 @@ public void delete(String key) throws IOException, JetStreamApiException { */ @Override public void delete(String key, long expectedRevision) throws IOException, JetStreamApiException { - validateNonWildcardKvKeyRequired(key); Headers h = getDeleteHeaders().put(EXPECTED_LAST_SUB_SEQ_HDR, Long.toString(expectedRevision)); - _write(key, null, h).getSeqno(); + _write(key, null, h); } /** diff --git a/src/main/java/io/nats/client/impl/NatsKeyValueWatchSubscription.java b/src/main/java/io/nats/client/impl/NatsKeyValueWatchSubscription.java index c63ce8fe5..10383d5d2 100644 --- a/src/main/java/io/nats/client/impl/NatsKeyValueWatchSubscription.java +++ b/src/main/java/io/nats/client/impl/NatsKeyValueWatchSubscription.java @@ -30,10 +30,10 @@ public NatsKeyValueWatchSubscription(NatsKeyValue kv, String keyPattern, KeyValu public NatsKeyValueWatchSubscription(NatsKeyValue kv, List keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption... watchOptions) throws IOException, JetStreamApiException { super(kv.js); - kwWatchInit(kv, keyPatterns, watcher, fromRevision, watchOptions); + kvWatchInit(kv, keyPatterns, watcher, fromRevision, watchOptions); } - private void kwWatchInit(NatsKeyValue kv, List keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption[] watchOptions) throws IOException, JetStreamApiException { + private void kvWatchInit(NatsKeyValue kv, List keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption[] watchOptions) throws IOException, JetStreamApiException { // figure out the result options boolean headersOnly = false; boolean ignoreDeletes = false; diff --git a/src/test/java/io/nats/client/impl/KeyValueTests.java b/src/test/java/io/nats/client/impl/KeyValueTests.java index c67f783a5..c368b74d7 100644 --- a/src/test/java/io/nats/client/impl/KeyValueTests.java +++ b/src/test/java/io/nats/client/impl/KeyValueTests.java @@ -67,17 +67,17 @@ public void testWorkflow() throws Exception { .build(); KeyValueStatus status = kvm.create(kvc); - assertInitialStatus(status, bucket, desc, metadata); + assertInitialStatus(status, bucket, desc); // get the kv context for the specific bucket KeyValue kv = nc.keyValue(bucket); assertEquals(bucket, kv.getBucketName()); status = kv.getStatus(); - assertInitialStatus(status, bucket, desc, metadata); + assertInitialStatus(status, bucket, desc); KeyValue kv2 = nc.keyValue(bucket, KeyValueOptions.builder(DEFAULT_JS_OPTIONS).build()); // coverage assertEquals(bucket, kv2.getBucketName()); - assertInitialStatus(kv2.getStatus(), bucket, desc, metadata); + assertInitialStatus(kv2.getStatus(), bucket, desc); // Put some keys. Each key is put in a subject in the bucket (stream) // The put returns the sequence number in the bucket (stream) @@ -143,7 +143,7 @@ public void testWorkflow() throws Exception { status = kvm.getStatus(bucket); assertState(status, 4, 4); - // if the key has been deleted no etnry is returned + // if the key has been deleted no entry is returned assertNull(kv.get(byteKey)); // if the key does not exist (no history) there is no entry @@ -306,9 +306,8 @@ private static void assertState(KeyValueStatus status, int entryCount, int lastS assertEquals(status.getByteCount(), status.getBackingStreamInfo().getStreamState().getByteCount()); } - private void assertInitialStatus(KeyValueStatus status, String bucket, String desc, Map metadata) { - KeyValueConfiguration kvc; - kvc = status.getConfiguration(); + private void assertInitialStatus(KeyValueStatus status, String bucket, String desc) { + KeyValueConfiguration kvc = status.getConfiguration(); assertEquals(bucket, status.getBucketName()); assertEquals(bucket, kvc.getBucketName()); assertEquals(desc, status.getDescription()); @@ -483,10 +482,11 @@ public void testMaxHistoryPerKey() throws Exception { .build()); KeyValue kv = nc.keyValue(bucket1); - kv.put(KEY, 1); - kv.put(KEY, 2); + String key = key(); + kv.put(key, 1); + kv.put(key, 2); - List history = kv.history(KEY); + List history = kv.history(key); assertEquals(1, history.size()); assertEquals(2, history.get(0).getValueAsLong()); @@ -496,7 +496,7 @@ public void testMaxHistoryPerKey() throws Exception { .storageType(StorageType.Memory) .build()); - String key = key(); + key = key(); kv = nc.keyValue(bucket2); kv.put(key, 1); kv.put(key, 2); @@ -514,9 +514,11 @@ public void testCreateUpdate() throws Exception { jsServer.run(nc -> { KeyValueManagement kvm = nc.keyValueManagement(); - assertThrows(JetStreamApiException.class, () -> kvm.getStatus(BUCKET)); - String bucket = bucket(); + + // doesn't exist yet + assertThrows(JetStreamApiException.class, () -> kvm.getStatus(bucket)); + KeyValueStatus kvs = kvm.create(KeyValueConfiguration.builder() .name(bucket) .storageType(StorageType.Memory)