Example usage for java.util.concurrent.atomic AtomicInteger incrementAndGet

List of usage examples for java.util.concurrent.atomic AtomicInteger incrementAndGet

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicInteger incrementAndGet.

Prototype

public final int incrementAndGet() 

Source Link

Document

Atomically increments the current value, with memory effects as specified by VarHandle#getAndAdd .

Usage

From source file:com.squarespace.template.CompilerTest.java

@Test
public void testLoggingHook() throws CodeException {
    final AtomicInteger count = new AtomicInteger();
    LoggingHook loggingHook = new LoggingHook() {
        @Override//  www.ja v a  2 s .  co m
        public void log(Exception e) {
            count.incrementAndGet();
            assertTrue(e instanceof NullPointerException);
        }
    };
    Context ctx = COMPILER.newExecutor().template("{@|npe}").json("123").safeExecution(true)
            .loggingHook(loggingHook).execute();
    assertEquals(count.get(), 1);
    assertEquals(ctx.getErrors().size(), 1);
    assertEquals(ctx.getErrors().get(0).getType(), ExecuteErrorType.UNEXPECTED_ERROR);
}

From source file:com.stratio.decision.unit.engine.validator.BaseRegularExpressionValidatorTest.java

@Ignore
@Test//from   w ww. j  av  a2  s.co m
public void mixedMessagesTest() {
    AtomicInteger count = new AtomicInteger(0);
    for (StratioStreamingMessage message : getMixedMessages()) {
        try {
            this.test(message);
        } catch (RequestValidationException e) {
            count.incrementAndGet();
        }
    }
    Assert.assertTrue(getBadStrings().length <= count.get());
}

From source file:com.amazonaws.http.DelegatingDnsResolverTest.java

@Test
public void testDelegatingDnsResolverCallsResolveOnDelegate() throws Exception {
    final AtomicInteger timesCalled = new AtomicInteger();

    DnsResolver delegate = new DnsResolver() {
        @Override//from  www. java  2  s .  c om
        public InetAddress[] resolve(String host) throws UnknownHostException {
            timesCalled.incrementAndGet();
            return new InetAddress[0];
        }
    };

    org.apache.http.conn.DnsResolver resolver = new DelegatingDnsResolver(delegate);

    resolver.resolve("localhost");

    assertEquals("Delegate Resolver should have been executed", 1, timesCalled.get());

}

From source file:strat.mining.multipool.stats.service.impl.RequestStatsLoggingServiceImpl.java

@Override
public void donnatorRequest(String bitcoinAddress) {
    AtomicInteger counter = donatorsRequests.get(bitcoinAddress);
    if (counter == null) {
        counter = new AtomicInteger(0);
        donatorsRequests.put(bitcoinAddress, counter);
    }/*from   ww  w .  j av  a  2 s  .  c o  m*/
    counter.incrementAndGet();
}

From source file:com.adobe.acs.commons.workflow.process.impl.SyncSmartTagsToXmpMetadataNodeProcess.java

private void createSequenceItemResource(Asset asset, ProcessArgs processArgs, ResourceResolver resourceResolver,
        Resource parentResource, AtomicInteger count, ValueMap properties) {
    try {/* w  ww  . j a  va 2 s  . co  m*/
        resourceResolver.create(parentResource, String.valueOf(count.incrementAndGet()),
                new ImmutableMap.Builder<String, Object>()
                        .put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED)
                        .put("xmpNodeType", "xmpStruct")
                        .put(processArgs.getNameProperty(), properties.get(PN_SMART_TAG_NAME, String.class))
                        .put(processArgs.getConfidenceProperty(),
                                properties.get(PN_SMART_TAG_CONFIDENCE, Double.class))
                        .build());
    } catch (PersistenceException e) {
        log.error("Unable to sync Smart Tag [ {} ] to XMP Metadata structure for asset [ {} ]",
                properties.get("name", String.class), asset.getPath(), e);
    }
}

From source file:com.shopzilla.hadoop.mapreduce.MiniMRClusterContextPigTest.java

@Test
public void testPig() throws Exception {
    final AtomicInteger inputRecordCount = new AtomicInteger(0);
    miniMRClusterContext.processData(new Path("/user/test/keywords_data"), new Function<String, Void>() {
        @Override//from   w ww.  jav a 2 s  .c o m
        public Void apply(String line) {
            inputRecordCount.incrementAndGet();
            return null;
        }
    });

    Map<String, String> params = ImmutableMap.<String, String>builder().put("INPUT", "/user/test/keywords_data")
            .put("OUTPUT", "/user/test/keywords_output").build();
    PigServer pigServer = miniMRClusterContext.getPigServer();
    pigServer.registerScript(new ClassPathResource("some_pig_script.pig").getInputStream(), params);
    pigServer.setBatchOn();
    pigServer.executeBatch();

    final AtomicInteger outputRecordCount = new AtomicInteger(0);

    miniMRClusterContext.processData(new Path("/user/test/keywords_output"), new Function<String, Void>() {
        @Override
        public Void apply(String line) {
            outputRecordCount.incrementAndGet();
            return null;
        }
    });

    assertEquals(inputRecordCount.intValue(), outputRecordCount.intValue());
}

From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java

@Test
public void testDeadlockRetry() throws Exception {
    final AtomicInteger i = new AtomicInteger();
    final int returnVal = new Random().nextInt();
    int result = DaoUtils.deadlockRetry(new Callable<Integer>() {
        @Override//www  . ja  v  a2  s . c  o m
        public Integer call() throws Exception {
            if (i.incrementAndGet() < 5) {
                throw new DeadlockLoserDataAccessException("My fake exception", null);
            }
            return returnVal;
        }
    });
    assertEquals(i.get(), 5);
    assertEquals(result, returnVal);
}

From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java

@Test
public void testDeadlockRetryNestedException() throws Exception {
    final AtomicInteger i = new AtomicInteger();
    final int returnVal = new Random().nextInt();
    int result = DaoUtils.deadlockRetry(new Callable<Integer>() {
        @Override//from   ww w .  ja v a  2 s  .c  o m
        public Integer call() throws Exception {
            if (i.incrementAndGet() < 5) {
                throw new RuntimeException(new DeadlockLoserDataAccessException("My fake exception", null));
            }
            return returnVal;
        }
    });
    assertEquals(i.get(), 5);
    assertEquals(result, returnVal);
}

From source file:io.wcm.caravan.pipeline.impl.JsonPipelineMultipleSubscriptionsTest.java

private void initPipelines(AtomicInteger subscribeCount) {
    Observable<CaravanHttpResponse> sourceObservable = Observable.create(subscriber -> {
        subscribeCount.incrementAndGet();
        subscriber.onNext(getJsonResponse(200, "{}", 0));
        subscriber.onCompleted();/*w ww  .j  a  va  2 s .  com*/
    });

    firstStep = new JsonPipelineImpl(new CaravanHttpRequestBuilder().build(), sourceObservable,
            getJsonPipelineContext());
    secondStep = firstStep.applyAction(action);
    thirdStep = secondStep.merge(newPipelineWithResponseBody("{name:'abc'}"));
    when(action.execute(any(), any())).thenReturn(firstStep.getOutput());
}

From source file:com.graphaware.reco.generic.stats.DefaultStatistics.java

/**
 * {@inheritDoc}/*from  ww w .j a va2  s.com*/
 */
@Override
public void incrementStatistic(String task, String name) {
    ConcurrentMap<String, Object> taskStats = getStatistics(task);

    AtomicInteger count = (AtomicInteger) taskStats.get(name);
    if (count == null) {
        taskStats.putIfAbsent(name, new AtomicInteger());
        count = (AtomicInteger) taskStats.get(name);
    }

    count.incrementAndGet();
}