Committed by
Gerrit Code Review
Add newer counter functions to the test application
Change-Id: I4675ceaeef7341426c5b644789eab64d4df84630
Showing
1 changed file
with
24 additions
and
3 deletions
... | @@ -43,11 +43,20 @@ public class CounterTestIncrementCommand extends AbstractShellCommand { | ... | @@ -43,11 +43,20 @@ public class CounterTestIncrementCommand extends AbstractShellCommand { |
43 | required = false, multiValued = false) | 43 | required = false, multiValued = false) |
44 | private boolean inMemory = false; | 44 | private boolean inMemory = false; |
45 | 45 | ||
46 | + @Option(name = "-g", aliases = "--getFirst", description = "get the counter's value before adding", | ||
47 | + required = false, multiValued = false) | ||
48 | + private boolean getFirst = false; | ||
49 | + | ||
46 | @Argument(index = 0, name = "counter", | 50 | @Argument(index = 0, name = "counter", |
47 | description = "Counter name", | 51 | description = "Counter name", |
48 | required = true, multiValued = false) | 52 | required = true, multiValued = false) |
49 | String counter = null; | 53 | String counter = null; |
50 | 54 | ||
55 | + @Argument(index = 1, name = "delta", | ||
56 | + description = "Long to add to the counter", | ||
57 | + required = false, multiValued = false) | ||
58 | + Long delta = null; | ||
59 | + | ||
51 | AsyncAtomicCounter atomicCounter; | 60 | AsyncAtomicCounter atomicCounter; |
52 | 61 | ||
53 | 62 | ||
... | @@ -64,10 +73,22 @@ public class CounterTestIncrementCommand extends AbstractShellCommand { | ... | @@ -64,10 +73,22 @@ public class CounterTestIncrementCommand extends AbstractShellCommand { |
64 | .withName(counter) | 73 | .withName(counter) |
65 | .buildAsyncCounter(); | 74 | .buildAsyncCounter(); |
66 | } | 75 | } |
67 | - | 76 | + CompletableFuture<Long> result; |
68 | - CompletableFuture<Long> result = atomicCounter.incrementAndGet(); | 77 | + if (delta != null) { |
78 | + if (getFirst) { | ||
79 | + result = atomicCounter.getAndAdd(delta); | ||
80 | + } else { | ||
81 | + result = atomicCounter.addAndGet(delta); | ||
82 | + } | ||
83 | + } else { | ||
84 | + if (getFirst) { | ||
85 | + result = atomicCounter.getAndIncrement(); | ||
86 | + } else { | ||
87 | + result = atomicCounter.incrementAndGet(); | ||
88 | + } | ||
89 | + } | ||
69 | try { | 90 | try { |
70 | - print("%s was incremented to %d", counter, result.get(3, TimeUnit.SECONDS)); | 91 | + print("%s was updated to %d", counter, result.get(3, TimeUnit.SECONDS)); |
71 | } catch (InterruptedException e) { | 92 | } catch (InterruptedException e) { |
72 | return; | 93 | return; |
73 | } catch (ExecutionException e) { | 94 | } catch (ExecutionException e) { | ... | ... |
-
Please register or login to post a comment