Madan Jampani
Committed by Gerrit Code Review

Default ConsistentMap consistency level to SEQUENTIAL and reenable all Atomix unit tests

Change-Id: Ic04ff81fbaaa7c007f20077391a72fdfa9fd382a
...@@ -236,11 +236,8 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap> ...@@ -236,11 +236,8 @@ public class AtomixConsistentMap extends Resource<AtomixConsistentMap>
236 @Override 236 @Override
237 public synchronized CompletableFuture<Void> addListener(MapEventListener<String, byte[]> listener) { 237 public synchronized CompletableFuture<Void> addListener(MapEventListener<String, byte[]> listener) {
238 if (!mapEventListeners.isEmpty()) { 238 if (!mapEventListeners.isEmpty()) {
239 - if (mapEventListeners.add(listener)) { 239 + mapEventListeners.add(listener);
240 - return CompletableFuture.completedFuture(new ChangeListener(listener)).thenApply(v -> null); 240 + return CompletableFuture.completedFuture(null);
241 - } else {
242 - return CompletableFuture.completedFuture(null);
243 - }
244 } 241 }
245 mapEventListeners.add(listener); 242 mapEventListeners.add(listener);
246 return submit(new AtomixConsistentMapCommands.Listen()).thenApply(v -> null); 243 return submit(new AtomixConsistentMapCommands.Listen()).thenApply(v -> null);
......
...@@ -52,7 +52,7 @@ public final class AtomixConsistentMapCommands { ...@@ -52,7 +52,7 @@ public final class AtomixConsistentMapCommands {
52 52
53 @Override 53 @Override
54 public ConsistencyLevel consistency() { 54 public ConsistencyLevel consistency() {
55 - return ConsistencyLevel.LINEARIZABLE; 55 + return ConsistencyLevel.SEQUENTIAL;
56 } 56 }
57 57
58 @Override 58 @Override
...@@ -78,7 +78,7 @@ public final class AtomixConsistentMapCommands { ...@@ -78,7 +78,7 @@ public final class AtomixConsistentMapCommands {
78 78
79 @Override 79 @Override
80 public ConsistencyLevel consistency() { 80 public ConsistencyLevel consistency() {
81 - return ConsistencyLevel.BOUNDED_LINEARIZABLE; 81 + return ConsistencyLevel.SEQUENTIAL;
82 } 82 }
83 83
84 @Override 84 @Override
......
...@@ -337,10 +337,9 @@ public class AtomixConsistentMapState extends ResourceStateMachine implements Se ...@@ -337,10 +337,9 @@ public class AtomixConsistentMapState extends ResourceStateMachine implements Se
337 * 337 *
338 * @param commit unlisten commit 338 * @param commit unlisten commit
339 */ 339 */
340 - protected void unlisten( 340 + protected void unlisten(Commit<? extends Unlisten> commit) {
341 - Commit<? extends Unlisten> commit) {
342 try { 341 try {
343 - Commit<? extends Listen> listener = listeners.remove(commit.session()); 342 + Commit<? extends Listen> listener = listeners.remove(commit.session().id());
344 if (listener != null) { 343 if (listener != null) {
345 listener.close(); 344 listener.close();
346 } 345 }
......
...@@ -21,10 +21,11 @@ import static org.junit.Assert.*; ...@@ -21,10 +21,11 @@ import static org.junit.Assert.*;
21 import java.util.Arrays; 21 import java.util.Arrays;
22 import java.util.ConcurrentModificationException; 22 import java.util.ConcurrentModificationException;
23 import java.util.List; 23 import java.util.List;
24 +import java.util.concurrent.ArrayBlockingQueue;
25 +import java.util.concurrent.BlockingQueue;
24 import java.util.concurrent.CompletionException; 26 import java.util.concurrent.CompletionException;
25 import java.util.stream.Collectors; 27 import java.util.stream.Collectors;
26 28
27 -import org.junit.Ignore;
28 import org.junit.Test; 29 import org.junit.Test;
29 import org.onlab.util.Tools; 30 import org.onlab.util.Tools;
30 import org.onosproject.store.primitives.MapUpdate; 31 import org.onosproject.store.primitives.MapUpdate;
...@@ -34,12 +35,12 @@ import org.onosproject.store.service.MapEventListener; ...@@ -34,12 +35,12 @@ import org.onosproject.store.service.MapEventListener;
34 import org.onosproject.store.service.MapTransaction; 35 import org.onosproject.store.service.MapTransaction;
35 import org.onosproject.store.service.Versioned; 36 import org.onosproject.store.service.Versioned;
36 37
38 +import com.google.common.base.Throwables;
37 import com.google.common.collect.Sets; 39 import com.google.common.collect.Sets;
38 40
39 /** 41 /**
40 * Unit tests for {@link AtomixConsistentMap}. 42 * Unit tests for {@link AtomixConsistentMap}.
41 */ 43 */
42 -@Ignore
43 public class AtomixConsistentMapTest extends AtomixTestBase { 44 public class AtomixConsistentMapTest extends AtomixTestBase {
44 45
45 @Override 46 @Override
...@@ -285,55 +286,52 @@ public class AtomixConsistentMapTest extends AtomixTestBase { ...@@ -285,55 +286,52 @@ public class AtomixConsistentMapTest extends AtomixTestBase {
285 TestMapEventListener listener = new TestMapEventListener(); 286 TestMapEventListener listener = new TestMapEventListener();
286 287
287 // add listener; insert new value into map and verify an INSERT event is received. 288 // add listener; insert new value into map and verify an INSERT event is received.
288 - map.addListener(listener).join(); 289 + map.addListener(listener).thenCompose(v -> map.put("foo", value1)).join();
289 - map.put("foo", value1).join(); 290 + MapEvent<String, byte[]> event = listener.event();
290 - assertNotNull(listener.event()); 291 + assertNotNull(event);
291 - assertEquals(MapEvent.Type.INSERT, listener.event().type()); 292 + assertEquals(MapEvent.Type.INSERT, event.type());
292 - assertTrue(Arrays.equals(value1, listener.event().newValue().value())); 293 + assertTrue(Arrays.equals(value1, event.newValue().value()));
293 - listener.clearEvent();
294 294
295 // remove listener and verify listener is not notified. 295 // remove listener and verify listener is not notified.
296 - map.removeListener(listener).join(); 296 + map.removeListener(listener).thenCompose(v -> map.put("foo", value2)).join();
297 - map.put("foo", value2).join(); 297 + assertFalse(listener.eventReceived());
298 - assertNull(listener.event());
299 298
300 // add the listener back and verify UPDATE events are received correctly 299 // add the listener back and verify UPDATE events are received correctly
301 - map.addListener(listener).join(); 300 + map.addListener(listener).thenCompose(v -> map.put("foo", value3)).join();
302 - map.put("foo", value3).join(); 301 + event = listener.event();
303 - assertNotNull(listener.event()); 302 + assertNotNull(event);
304 - assertEquals(MapEvent.Type.UPDATE, listener.event().type()); 303 + assertEquals(MapEvent.Type.UPDATE, event.type());
305 - assertTrue(Arrays.equals(value3, listener.event().newValue().value())); 304 + assertTrue(Arrays.equals(value3, event.newValue().value()));
306 - listener.clearEvent();
307 305
308 // perform a non-state changing operation and verify no events are received. 306 // perform a non-state changing operation and verify no events are received.
309 map.putIfAbsent("foo", value1).join(); 307 map.putIfAbsent("foo", value1).join();
310 - assertNull(listener.event()); 308 + assertFalse(listener.eventReceived());
311 309
312 // verify REMOVE events are received correctly. 310 // verify REMOVE events are received correctly.
313 map.remove("foo").join(); 311 map.remove("foo").join();
314 - assertNotNull(listener.event()); 312 + event = listener.event();
315 - assertEquals(MapEvent.Type.REMOVE, listener.event().type()); 313 + assertNotNull(event);
316 - assertTrue(Arrays.equals(value3, listener.event().oldValue().value())); 314 + assertEquals(MapEvent.Type.REMOVE, event.type());
317 - listener.clearEvent(); 315 + assertTrue(Arrays.equals(value3, event.oldValue().value()));
318 316
319 // verify compute methods also generate events. 317 // verify compute methods also generate events.
320 map.computeIf("foo", v -> v == null, (k, v) -> value1).join(); 318 map.computeIf("foo", v -> v == null, (k, v) -> value1).join();
321 - assertNotNull(listener.event()); 319 + event = listener.event();
322 - assertEquals(MapEvent.Type.INSERT, listener.event().type()); 320 + assertNotNull(event);
323 - assertTrue(Arrays.equals(value1, listener.event().newValue().value())); 321 + assertEquals(MapEvent.Type.INSERT, event.type());
324 - listener.clearEvent(); 322 + assertTrue(Arrays.equals(value1, event.newValue().value()));
325 323
326 map.compute("foo", (k, v) -> value2).join(); 324 map.compute("foo", (k, v) -> value2).join();
327 - assertNotNull(listener.event()); 325 + event = listener.event();
328 - assertEquals(MapEvent.Type.UPDATE, listener.event().type()); 326 + assertNotNull(event);
329 - assertTrue(Arrays.equals(value2, listener.event().newValue().value())); 327 + assertEquals(MapEvent.Type.UPDATE, event.type());
330 - listener.clearEvent(); 328 + assertTrue(Arrays.equals(value2, event.newValue().value()));
331 329
332 map.computeIf("foo", v -> Arrays.equals(v, value2), (k, v) -> null).join(); 330 map.computeIf("foo", v -> Arrays.equals(v, value2), (k, v) -> null).join();
333 - assertNotNull(listener.event()); 331 + event = listener.event();
334 - assertEquals(MapEvent.Type.REMOVE, listener.event().type()); 332 + assertNotNull(event);
335 - assertTrue(Arrays.equals(value2, listener.event().oldValue().value())); 333 + assertEquals(MapEvent.Type.REMOVE, event.type());
336 - listener.clearEvent(); 334 + assertTrue(Arrays.equals(value2, event.oldValue().value()));
337 335
338 map.removeListener(listener).join(); 336 map.removeListener(listener).join();
339 } 337 }
...@@ -359,7 +357,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase { ...@@ -359,7 +357,7 @@ public class AtomixConsistentMapTest extends AtomixTestBase {
359 map.prepare(tx).thenAccept(result -> { 357 map.prepare(tx).thenAccept(result -> {
360 assertEquals(true, result); 358 assertEquals(true, result);
361 }).join(); 359 }).join();
362 - assertNull(listener.event()); 360 + assertFalse(listener.eventReceived());
363 361
364 map.size().thenAccept(result -> { 362 map.size().thenAccept(result -> {
365 assertTrue(result == 0); 363 assertTrue(result == 0);
...@@ -376,21 +374,21 @@ public class AtomixConsistentMapTest extends AtomixTestBase { ...@@ -376,21 +374,21 @@ public class AtomixConsistentMapTest extends AtomixTestBase {
376 assertEquals(ConcurrentModificationException.class, e.getCause().getClass()); 374 assertEquals(ConcurrentModificationException.class, e.getCause().getClass());
377 } 375 }
378 376
379 - assertNull(listener.event()); 377 + assertFalse(listener.eventReceived());
380 378
381 map.commit(tx.transactionId()).join(); 379 map.commit(tx.transactionId()).join();
382 - assertNotNull(listener.event()); 380 + MapEvent<String, byte[]> event = listener.event();
383 - assertEquals(MapEvent.Type.INSERT, listener.event().type()); 381 + assertNotNull(event);
384 - assertTrue(Arrays.equals(value1, listener.event().newValue().value())); 382 + assertEquals(MapEvent.Type.INSERT, event.type());
385 - listener.clearEvent(); 383 + assertTrue(Arrays.equals(value1, event.newValue().value()));
386 384
387 map.put("foo", value2).thenAccept(result -> { 385 map.put("foo", value2).thenAccept(result -> {
388 assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1)); 386 assertTrue(Arrays.equals(Versioned.valueOrElse(result, null), value1));
389 }).join(); 387 }).join();
390 - assertNotNull(listener.event()); 388 + event = listener.event();
391 - assertEquals(MapEvent.Type.UPDATE, listener.event().type()); 389 + assertNotNull(event);
392 - assertTrue(Arrays.equals(value2, listener.event().newValue().value())); 390 + assertEquals(MapEvent.Type.UPDATE, event.type());
393 - listener.clearEvent(); 391 + assertTrue(Arrays.equals(value2, event.newValue().value()));
394 } 392 }
395 393
396 protected void transactionRollbackTests(int clusterSize) throws Throwable { 394 protected void transactionRollbackTests(int clusterSize) throws Throwable {
...@@ -412,10 +410,10 @@ public class AtomixConsistentMapTest extends AtomixTestBase { ...@@ -412,10 +410,10 @@ public class AtomixConsistentMapTest extends AtomixTestBase {
412 map.prepare(tx).thenAccept(result -> { 410 map.prepare(tx).thenAccept(result -> {
413 assertEquals(true, result); 411 assertEquals(true, result);
414 }).join(); 412 }).join();
415 - assertNull(listener.event()); 413 + assertFalse(listener.eventReceived());
416 414
417 map.rollback(tx.transactionId()).join(); 415 map.rollback(tx.transactionId()).join();
418 - assertNull(listener.event()); 416 + assertFalse(listener.eventReceived());
419 417
420 map.get("foo").thenAccept(result -> { 418 map.get("foo").thenAccept(result -> {
421 assertNull(result); 419 assertNull(result);
...@@ -424,27 +422,31 @@ public class AtomixConsistentMapTest extends AtomixTestBase { ...@@ -424,27 +422,31 @@ public class AtomixConsistentMapTest extends AtomixTestBase {
424 map.put("foo", value2).thenAccept(result -> { 422 map.put("foo", value2).thenAccept(result -> {
425 assertNull(result); 423 assertNull(result);
426 }).join(); 424 }).join();
427 - assertNotNull(listener.event()); 425 + MapEvent<String, byte[]> event = listener.event();
428 - assertEquals(MapEvent.Type.INSERT, listener.event().type()); 426 + assertNotNull(event);
429 - assertTrue(Arrays.equals(value2, listener.event().newValue().value())); 427 + assertEquals(MapEvent.Type.INSERT, event.type());
430 - listener.clearEvent(); 428 + assertTrue(Arrays.equals(value2, event.newValue().value()));
431 } 429 }
432 430
433 private static class TestMapEventListener implements MapEventListener<String, byte[]> { 431 private static class TestMapEventListener implements MapEventListener<String, byte[]> {
434 432
435 - MapEvent<String, byte[]> event; 433 + private final BlockingQueue<MapEvent<String, byte[]>> queue = new ArrayBlockingQueue<>(1);
436 434
437 @Override 435 @Override
438 public void event(MapEvent<String, byte[]> event) { 436 public void event(MapEvent<String, byte[]> event) {
439 - this.event = event; 437 + try {
438 + queue.put(event);
439 + } catch (InterruptedException e) {
440 + Throwables.propagate(e);
441 + }
440 } 442 }
441 443
442 - public MapEvent<String, byte[]> event() { 444 + public boolean eventReceived() {
443 - return event; 445 + return !queue.isEmpty();
444 } 446 }
445 447
446 - public void clearEvent() { 448 + public MapEvent<String, byte[]> event() throws InterruptedException {
447 - event = null; 449 + return queue.take();
448 } 450 }
449 } 451 }
450 } 452 }
......
...@@ -20,7 +20,6 @@ import java.util.Queue; ...@@ -20,7 +20,6 @@ import java.util.Queue;
20 import java.util.concurrent.CompletableFuture; 20 import java.util.concurrent.CompletableFuture;
21 import java.util.function.Consumer; 21 import java.util.function.Consumer;
22 22
23 -import org.junit.Ignore;
24 import org.junit.Test; 23 import org.junit.Test;
25 24
26 import static org.junit.Assert.*; 25 import static org.junit.Assert.*;
...@@ -35,7 +34,6 @@ import io.atomix.resource.ResourceType; ...@@ -35,7 +34,6 @@ import io.atomix.resource.ResourceType;
35 /** 34 /**
36 * Unit tests for {@link AtomixLeaderElector}. 35 * Unit tests for {@link AtomixLeaderElector}.
37 */ 36 */
38 -@Ignore
39 public class AtomixLeaderElectorTest extends AtomixTestBase { 37 public class AtomixLeaderElectorTest extends AtomixTestBase {
40 38
41 NodeId node1 = new NodeId("node1"); 39 NodeId node1 = new NodeId("node1");
......
...@@ -17,7 +17,6 @@ package org.onosproject.store.primitives.resources.impl; ...@@ -17,7 +17,6 @@ package org.onosproject.store.primitives.resources.impl;
17 17
18 import static org.junit.Assert.*; 18 import static org.junit.Assert.*;
19 19
20 -import org.junit.Ignore;
21 import org.junit.Test; 20 import org.junit.Test;
22 21
23 import io.atomix.Atomix; 22 import io.atomix.Atomix;
...@@ -27,7 +26,6 @@ import io.atomix.variables.DistributedLong; ...@@ -27,7 +26,6 @@ import io.atomix.variables.DistributedLong;
27 /** 26 /**
28 * Unit tests for {@link AtomixCounter}. 27 * Unit tests for {@link AtomixCounter}.
29 */ 28 */
30 -@Ignore
31 public class AtomixLongTest extends AtomixTestBase { 29 public class AtomixLongTest extends AtomixTestBase {
32 30
33 @Override 31 @Override
......