Package io.vertx.core.shareddata

Examples of io.vertx.core.shareddata.Counter


  @Test
  public void testIllegalArguments() throws Exception {
    assertNullPointerException(() -> getVertx().sharedData().getCounter(null, ar -> {}));
    assertNullPointerException(() -> getVertx().sharedData().getCounter("foo", null));
    getVertx().sharedData().getCounter("foo", ar -> {
      Counter counter = ar.result();
      assertNullPointerException(() -> counter.get(null));
      assertNullPointerException(() -> counter.incrementAndGet(null));
      assertNullPointerException(() -> counter.getAndIncrement(null));
      assertNullPointerException(() -> counter.decrementAndGet(null));
      assertNullPointerException(() -> counter.addAndGet(1, null));
      assertNullPointerException(() -> counter.getAndAdd(1, null));
      assertNullPointerException(() -> counter.compareAndSet(1, 1, null));
      testComplete();
    });
    await();
  }
View Full Code Here


  @Test
  public void testGet() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.get(ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(0l, ar2.result().longValue());
        testComplete();
      });
    });
View Full Code Here

  @Test
  public void testIncrementAndGet() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.incrementAndGet(ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(1l, ar2.result().longValue());
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.incrementAndGet(ar4 -> {
            assertTrue(ar4.succeeded());
            assertEquals(2l, ar4.result().longValue());
            testComplete();
          });
        });
View Full Code Here

  @Test
  public void testGetAndIncrement() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.getAndIncrement(ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(0l, ar2.result().longValue());
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.getAndIncrement(ar4 -> {
            assertTrue(ar4.succeeded());
            assertEquals(1l, ar4.result().longValue());
            counter2.get(ar5 -> {
              assertTrue(ar5.succeeded());
              assertEquals(2l, ar5.result().longValue());
              testComplete();
            });
          });
View Full Code Here

  @Test
  public void testDecrementAndGet() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.decrementAndGet(ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(-1l, ar2.result().longValue());
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.decrementAndGet(ar4 -> {
            assertTrue(ar4.succeeded());
            assertEquals(-2l, ar4.result().longValue());
            testComplete();
          });
        });
View Full Code Here

  @Test
  public void testAddAndGet() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.addAndGet(2, ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(2l, ar2.result().longValue());
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.addAndGet(2l, ar4 -> {
            assertTrue(ar4.succeeded());
            assertEquals(4l, ar4.result().longValue());
            testComplete();
          });
        });
View Full Code Here

  @Test
  public void getAndAdd() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.getAndAdd(2, ar2 -> {
        assertTrue(ar2.succeeded());
        assertEquals(0l, ar2.result().longValue());
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.getAndAdd(2l, ar4 -> {
            assertTrue(ar4.succeeded());
            assertEquals(2l, ar4.result().longValue());
            counter2.get(ar5 -> {
              assertTrue(ar5.succeeded());
              assertEquals(4l, ar5.result().longValue());
              testComplete();
            });
          });
View Full Code Here

  @Test
  public void testCompareAndSet() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.compareAndSet(0l, 2l, onSuccess(result -> {
        getVertx().sharedData().getCounter("foo", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.compareAndSet(2l, 4l, ar4 -> {
            assertTrue(ar4.succeeded());
            assertTrue(ar4.result());
            counter2.compareAndSet(3l, 5l, ar5 -> {
              assertTrue(ar5.succeeded());
              assertFalse(ar5.result());
              testComplete();
            });
          });
View Full Code Here

  @Test
  public void testDifferentCounters() {
    getVertx().sharedData().getCounter("foo", ar -> {
      assertTrue(ar.succeeded());
      Counter counter = ar.result();
      counter.incrementAndGet(onSuccess(res -> {
        assertEquals(1l, res.longValue());
        getVertx().sharedData().getCounter("bar", ar3 -> {
          assertTrue(ar3.succeeded());
          Counter counter2 = ar3.result();
          counter2.incrementAndGet(ar4 -> {
            assertEquals(1l, ar4.result().longValue());
            counter.incrementAndGet(ar5 -> {
              assertEquals(2l, ar5.result().longValue());
              testComplete();
            });
View Full Code Here

    lock.acquire(timeout, resultHandler);
  }

  @Override
  public void getCounter(String name, Handler<AsyncResult<Counter>> resultHandler) {
    Counter counter = new AsynchronousCounter(vertx);
    Counter prev = counters.putIfAbsent(name, counter);
    if (prev != null) {
      counter = prev;
    }
    Counter theCounter = counter;
    Context context = vertx.getOrCreateContext();
    context.runOnContext(v -> resultHandler.handle(Future.completedFuture(theCounter)));
  }
View Full Code Here

TOP

Related Classes of io.vertx.core.shareddata.Counter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.