Skip to content

Commit e18c04e

Browse files
authored
KV Minor Changes (#1264)
No functional changes
1 parent 9c10628 commit e18c04e

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/main/java/io/nats/client/impl/NatsKeyValue.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public long put(String key, String value) throws IOException, JetStreamApiExcept
155155
*/
156156
@Override
157157
public long put(String key, Number value) throws IOException, JetStreamApiException {
158-
return put(key, value.toString().getBytes(StandardCharsets.US_ASCII));
158+
return _write(key, value.toString().getBytes(StandardCharsets.US_ASCII), null).getSeqno();
159159
}
160160

161161
/**
@@ -202,7 +202,6 @@ public long update(String key, String value, long expectedRevision) throws IOExc
202202
*/
203203
@Override
204204
public void delete(String key) throws IOException, JetStreamApiException {
205-
validateNonWildcardKvKeyRequired(key);
206205
_write(key, null, getDeleteHeaders());
207206
}
208207

@@ -211,9 +210,8 @@ public void delete(String key) throws IOException, JetStreamApiException {
211210
*/
212211
@Override
213212
public void delete(String key, long expectedRevision) throws IOException, JetStreamApiException {
214-
validateNonWildcardKvKeyRequired(key);
215213
Headers h = getDeleteHeaders().put(EXPECTED_LAST_SUB_SEQ_HDR, Long.toString(expectedRevision));
216-
_write(key, null, h).getSeqno();
214+
_write(key, null, h);
217215
}
218216

219217
/**

src/main/java/io/nats/client/impl/NatsKeyValueWatchSubscription.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public NatsKeyValueWatchSubscription(NatsKeyValue kv, String keyPattern, KeyValu
3030

3131
public NatsKeyValueWatchSubscription(NatsKeyValue kv, List<String> keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption... watchOptions) throws IOException, JetStreamApiException {
3232
super(kv.js);
33-
kwWatchInit(kv, keyPatterns, watcher, fromRevision, watchOptions);
33+
kvWatchInit(kv, keyPatterns, watcher, fromRevision, watchOptions);
3434
}
3535

36-
private void kwWatchInit(NatsKeyValue kv, List<String> keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption[] watchOptions) throws IOException, JetStreamApiException {
36+
private void kvWatchInit(NatsKeyValue kv, List<String> keyPatterns, KeyValueWatcher watcher, long fromRevision, KeyValueWatchOption[] watchOptions) throws IOException, JetStreamApiException {
3737
// figure out the result options
3838
boolean headersOnly = false;
3939
boolean ignoreDeletes = false;

src/test/java/io/nats/client/impl/KeyValueTests.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ public void testWorkflow() throws Exception {
6767
.build();
6868

6969
KeyValueStatus status = kvm.create(kvc);
70-
assertInitialStatus(status, bucket, desc, metadata);
70+
assertInitialStatus(status, bucket, desc);
7171

7272
// get the kv context for the specific bucket
7373
KeyValue kv = nc.keyValue(bucket);
7474
assertEquals(bucket, kv.getBucketName());
7575
status = kv.getStatus();
76-
assertInitialStatus(status, bucket, desc, metadata);
76+
assertInitialStatus(status, bucket, desc);
7777

7878
KeyValue kv2 = nc.keyValue(bucket, KeyValueOptions.builder(DEFAULT_JS_OPTIONS).build()); // coverage
7979
assertEquals(bucket, kv2.getBucketName());
80-
assertInitialStatus(kv2.getStatus(), bucket, desc, metadata);
80+
assertInitialStatus(kv2.getStatus(), bucket, desc);
8181

8282
// Put some keys. Each key is put in a subject in the bucket (stream)
8383
// The put returns the sequence number in the bucket (stream)
@@ -143,7 +143,7 @@ public void testWorkflow() throws Exception {
143143
status = kvm.getStatus(bucket);
144144
assertState(status, 4, 4);
145145

146-
// if the key has been deleted no etnry is returned
146+
// if the key has been deleted no entry is returned
147147
assertNull(kv.get(byteKey));
148148

149149
// 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
306306
assertEquals(status.getByteCount(), status.getBackingStreamInfo().getStreamState().getByteCount());
307307
}
308308

309-
private void assertInitialStatus(KeyValueStatus status, String bucket, String desc, Map<String, String> metadata) {
310-
KeyValueConfiguration kvc;
311-
kvc = status.getConfiguration();
309+
private void assertInitialStatus(KeyValueStatus status, String bucket, String desc) {
310+
KeyValueConfiguration kvc = status.getConfiguration();
312311
assertEquals(bucket, status.getBucketName());
313312
assertEquals(bucket, kvc.getBucketName());
314313
assertEquals(desc, status.getDescription());
@@ -483,10 +482,11 @@ public void testMaxHistoryPerKey() throws Exception {
483482
.build());
484483

485484
KeyValue kv = nc.keyValue(bucket1);
486-
kv.put(KEY, 1);
487-
kv.put(KEY, 2);
485+
String key = key();
486+
kv.put(key, 1);
487+
kv.put(key, 2);
488488

489-
List<KeyValueEntry> history = kv.history(KEY);
489+
List<KeyValueEntry> history = kv.history(key);
490490
assertEquals(1, history.size());
491491
assertEquals(2, history.get(0).getValueAsLong());
492492

@@ -496,7 +496,7 @@ public void testMaxHistoryPerKey() throws Exception {
496496
.storageType(StorageType.Memory)
497497
.build());
498498

499-
String key = key();
499+
key = key();
500500
kv = nc.keyValue(bucket2);
501501
kv.put(key, 1);
502502
kv.put(key, 2);
@@ -514,9 +514,11 @@ public void testCreateUpdate() throws Exception {
514514
jsServer.run(nc -> {
515515
KeyValueManagement kvm = nc.keyValueManagement();
516516

517-
assertThrows(JetStreamApiException.class, () -> kvm.getStatus(BUCKET));
518-
519517
String bucket = bucket();
518+
519+
// doesn't exist yet
520+
assertThrows(JetStreamApiException.class, () -> kvm.getStatus(bucket));
521+
520522
KeyValueStatus kvs = kvm.create(KeyValueConfiguration.builder()
521523
.name(bucket)
522524
.storageType(StorageType.Memory)

0 commit comments

Comments
 (0)