Committed by
Gerrit Code Review
stc work queue test improvements
Change-Id: I8b9335b0bbfdc8a447c5955bf3621962ff112cb2
Showing
6 changed files
with
43 additions
and
13 deletions
... | @@ -46,7 +46,7 @@ public class WorkQueueTestCommand extends AbstractShellCommand { | ... | @@ -46,7 +46,7 @@ public class WorkQueueTestCommand extends AbstractShellCommand { |
46 | 46 | ||
47 | @Argument(index = 1, name = "operation", | 47 | @Argument(index = 1, name = "operation", |
48 | description = "operation name. One of {add, addMutiple, " | 48 | description = "operation name. One of {add, addMutiple, " |
49 | - + "takeAndComplete, totalPending, totalInProgress, totalCompleted}", | 49 | + + "takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy}", |
50 | required = true, multiValued = false) | 50 | required = true, multiValued = false) |
51 | String operation = null; | 51 | String operation = null; |
52 | 52 | ||
... | @@ -95,9 +95,11 @@ public class WorkQueueTestCommand extends AbstractShellCommand { | ... | @@ -95,9 +95,11 @@ public class WorkQueueTestCommand extends AbstractShellCommand { |
95 | } else if (operation.equals("totalCompleted")) { | 95 | } else if (operation.equals("totalCompleted")) { |
96 | WorkQueueStats stats = get(queue.stats()); | 96 | WorkQueueStats stats = get(queue.stats()); |
97 | print("%d", stats.totalCompleted()); | 97 | print("%d", stats.totalCompleted()); |
98 | + } else if (operation.equals("destroy")) { | ||
99 | + get(queue.destroy()); | ||
98 | } else { | 100 | } else { |
99 | print("Invalid operation name. Valid operations names are:" | 101 | print("Invalid operation name. Valid operations names are:" |
100 | - + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted]"); | 102 | + + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy]"); |
101 | } | 103 | } |
102 | } | 104 | } |
103 | 105 | ... | ... |
... | @@ -29,10 +29,10 @@ import org.onosproject.store.service.MapEvent; | ... | @@ -29,10 +29,10 @@ import org.onosproject.store.service.MapEvent; |
29 | import org.onosproject.store.service.MapEventListener; | 29 | import org.onosproject.store.service.MapEventListener; |
30 | import org.onosproject.store.service.Serializer; | 30 | import org.onosproject.store.service.Serializer; |
31 | import org.onosproject.store.service.Versioned; | 31 | import org.onosproject.store.service.Versioned; |
32 | +import org.onosproject.utils.MeteringAgent; | ||
32 | 33 | ||
33 | import com.google.common.base.Throwables; | 34 | import com.google.common.base.Throwables; |
34 | import com.google.common.collect.Maps; | 35 | import com.google.common.collect.Maps; |
35 | -import org.onosproject.utils.MeteringAgent; | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Default implementation of a {@code AsyncAtomicValue}. | 38 | * Default implementation of a {@code AsyncAtomicValue}. |
... | @@ -56,6 +56,7 @@ public class DefaultAsyncAtomicValue<V> implements AsyncAtomicValue<V> { | ... | @@ -56,6 +56,7 @@ public class DefaultAsyncAtomicValue<V> implements AsyncAtomicValue<V> { |
56 | private static final String ADD_LISTENER = "addListener"; | 56 | private static final String ADD_LISTENER = "addListener"; |
57 | private static final String REMOVE_LISTENER = "removeListener"; | 57 | private static final String REMOVE_LISTENER = "removeListener"; |
58 | private static final String NOTIFY_LISTENER = "notifyListener"; | 58 | private static final String NOTIFY_LISTENER = "notifyListener"; |
59 | + private static final String DESTROY = "destroy"; | ||
59 | 60 | ||
60 | public DefaultAsyncAtomicValue(String name, Serializer serializer, AsyncConsistentMap<String, byte[]> backingMap) { | 61 | public DefaultAsyncAtomicValue(String name, Serializer serializer, AsyncConsistentMap<String, byte[]> backingMap) { |
61 | this.name = checkNotNull(name, "name must not be null"); | 62 | this.name = checkNotNull(name, "name must not be null"); |
... | @@ -70,6 +71,14 @@ public class DefaultAsyncAtomicValue<V> implements AsyncAtomicValue<V> { | ... | @@ -70,6 +71,14 @@ public class DefaultAsyncAtomicValue<V> implements AsyncAtomicValue<V> { |
70 | } | 71 | } |
71 | 72 | ||
72 | @Override | 73 | @Override |
74 | + public CompletableFuture<Void> destroy() { | ||
75 | + final MeteringAgent.Context newTimer = monitor.startTimer(DESTROY); | ||
76 | + return backingMap.remove(name) | ||
77 | + .whenComplete((r, e) -> newTimer.stop(e)) | ||
78 | + .thenApply(v -> null); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
73 | public CompletableFuture<Boolean> compareAndSet(V expect, V update) { | 82 | public CompletableFuture<Boolean> compareAndSet(V expect, V update) { |
74 | final MeteringAgent.Context newTimer = monitor.startTimer(COMPARE_AND_SET); | 83 | final MeteringAgent.Context newTimer = monitor.startTimer(COMPARE_AND_SET); |
75 | return backingMap.replace(name, serializer.encode(expect), serializer.encode(update)) | 84 | return backingMap.replace(name, serializer.encode(expect), serializer.encode(update)) | ... | ... |
... | @@ -7,9 +7,9 @@ import java.util.concurrent.Executor; | ... | @@ -7,9 +7,9 @@ import java.util.concurrent.Executor; |
7 | import java.util.function.Consumer; | 7 | import java.util.function.Consumer; |
8 | import java.util.stream.Collectors; | 8 | import java.util.stream.Collectors; |
9 | 9 | ||
10 | -import org.onosproject.store.service.WorkQueue; | ||
11 | import org.onosproject.store.service.Serializer; | 10 | import org.onosproject.store.service.Serializer; |
12 | import org.onosproject.store.service.Task; | 11 | import org.onosproject.store.service.Task; |
12 | +import org.onosproject.store.service.WorkQueue; | ||
13 | import org.onosproject.store.service.WorkQueueStats; | 13 | import org.onosproject.store.service.WorkQueueStats; |
14 | 14 | ||
15 | import com.google.common.collect.Collections2; | 15 | import com.google.common.collect.Collections2; |
... | @@ -73,4 +73,9 @@ public class DefaultDistributedWorkQueue<E> implements WorkQueue<E> { | ... | @@ -73,4 +73,9 @@ public class DefaultDistributedWorkQueue<E> implements WorkQueue<E> { |
73 | public CompletableFuture<Void> stopProcessing() { | 73 | public CompletableFuture<Void> stopProcessing() { |
74 | return backingQueue.stopProcessing(); | 74 | return backingQueue.stopProcessing(); |
75 | } | 75 | } |
76 | + | ||
77 | + @Override | ||
78 | + public CompletableFuture<Void> destroy() { | ||
79 | + return backingQueue.destroy(); | ||
80 | + } | ||
76 | } | 81 | } | ... | ... |
... | @@ -98,14 +98,18 @@ public class AtomixWorkQueueState extends ResourceStateMachine implements Sessi | ... | @@ -98,14 +98,18 @@ public class AtomixWorkQueueState extends ResourceStateMachine implements Sessi |
98 | } | 98 | } |
99 | 99 | ||
100 | protected void clear(Commit<? extends Clear> commit) { | 100 | protected void clear(Commit<? extends Clear> commit) { |
101 | - unassignedTasks.forEach(TaskHolder::complete); | 101 | + try { |
102 | - unassignedTasks.clear(); | 102 | + unassignedTasks.forEach(TaskHolder::complete); |
103 | - assignments.values().forEach(TaskAssignment::markComplete); | 103 | + unassignedTasks.clear(); |
104 | - assignments.clear(); | 104 | + assignments.values().forEach(TaskAssignment::markComplete); |
105 | - registeredWorkers.values().forEach(Commit::close); | 105 | + assignments.clear(); |
106 | - registeredWorkers.clear(); | 106 | + registeredWorkers.values().forEach(Commit::close); |
107 | - activeTasksPerSession.clear(); | 107 | + registeredWorkers.clear(); |
108 | - totalCompleted.set(0); | 108 | + activeTasksPerSession.clear(); |
109 | + totalCompleted.set(0); | ||
110 | + } finally { | ||
111 | + commit.close(); | ||
112 | + } | ||
109 | } | 113 | } |
110 | 114 | ||
111 | protected void register(Commit<? extends Register> commit) { | 115 | protected void register(Commit<? extends Register> commit) { | ... | ... |
... | @@ -30,6 +30,9 @@ | ... | @@ -30,6 +30,9 @@ |
30 | <import file="${ONOS_SCENARIOS}/dist-leader.xml"/> | 30 | <import file="${ONOS_SCENARIOS}/dist-leader.xml"/> |
31 | <dependency name="Distributed-Primitive-Leader" requires="Distributed-Primitive-Counter"/> | 31 | <dependency name="Distributed-Primitive-Leader" requires="Distributed-Primitive-Counter"/> |
32 | 32 | ||
33 | + <import file="${ONOS_SCENARIOS}/dist-work-queue.xml"/> | ||
34 | + <dependency name="Distributed-Primitive-WorkQueue" requires="Distributed-Primitive-Leader"/> | ||
35 | + | ||
33 | </group> | 36 | </group> |
34 | </scenario> | 37 | </scenario> |
35 | 38 | ... | ... |
... | @@ -30,6 +30,9 @@ | ... | @@ -30,6 +30,9 @@ |
30 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-InProgress-1" requires="^" | 30 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-InProgress-1" requires="^" |
31 | exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalInProgress --expect 0"/> | 31 | exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalInProgress --expect 0"/> |
32 | 32 | ||
33 | + <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-TotalCompleted-1" requires="^" | ||
34 | + exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalCompleted --expect 0"/> | ||
35 | + | ||
33 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-AddMultiple" requires="^" | 36 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-AddMultiple" requires="^" |
34 | exec="onos-execute-expect ${OCI} work-queue-test stc-test-work-queue addMultiple bar car --expect Done"/> | 37 | exec="onos-execute-expect ${OCI} work-queue-test stc-test-work-queue addMultiple bar car --expect Done"/> |
35 | 38 | ||
... | @@ -42,7 +45,11 @@ | ... | @@ -42,7 +45,11 @@ |
42 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-InProgress-2" requires="^" | 45 | <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-InProgress-2" requires="^" |
43 | exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalInProgress --expect 0"/> | 46 | exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalInProgress --expect 0"/> |
44 | 47 | ||
45 | - <!-- Since totalCompleted is a additive quantity, testing its value breaks when the test is run in a loop --> | 48 | + <step name="Distributed-Primitive-WorkQueue.Test-Queue-Check-TotalCompleted-2" requires="^" |
49 | + exec="onos-cluster-execute-expect work-queue-test stc-test-work-queue totalCompleted --expect 3"/> | ||
50 | + | ||
51 | + <step name="Distributed-Primitive-WorkQueue.Test-Queue-Destroy" requires="^" | ||
52 | + exec="onos ${OCI} work-queue-test stc-test-work-queue destroy"/> | ||
46 | 53 | ||
47 | <!--Check with check logs--> | 54 | <!--Check with check logs--> |
48 | <step name="Distributed-Primitive-WorkQueue.Check-Log-Exceptions" requires="^" | 55 | <step name="Distributed-Primitive-WorkQueue.Check-Log-Exceptions" requires="^" | ... | ... |
-
Please register or login to post a comment