List of usage examples for java.util.concurrent.atomic AtomicInteger incrementAndGet
public final int incrementAndGet()
From source file:com.asakusafw.lang.compiler.cli.BatchCompilerCliTest.java
/** * w/ scoped properties.//from www .j a v a2 s . com * @throws Exception if failed */ @Test public void execute_scoped_properties() throws Exception { File output = deployer.newFolder(); String[] args = strings(new Object[] { "--explore", files(ResourceUtil.findLibraryByClass(DummyBatch.class)), "--output", output, "--classAnalyzer", classes(DummyClassAnalyzer.class), "--batchCompiler", classes(DelegateBatchCompiler.class), "--include", classes(DummyBatch.class), "--externalPortProcessors", classes(DummyExternalPortProcessor.class), "--batchIdPrefix", "prefix.", "-P", "a=A", "-P", "b=B", "-P", "DummyBatch:b=!", "-P", "DummyBatch:c=C", "-P", "other:a=INVALID", }); AtomicInteger count = new AtomicInteger(); int status = execute(args, (context, batch) -> { count.incrementAndGet(); CompilerOptions options = context.getOptions(); assertThat(options.get("a", "?"), is("A")); assertThat(options.get("b", "?"), is("!")); assertThat(options.get("c", "?"), is("C")); }); assertThat(status, is(0)); assertThat(count.get(), is(1)); }
From source file:com.supermy.flume.interceptor.RuleThreadSearchAndReplaceInterceptor.java
@Override public List<Event> intercept(List<Event> events) { //todo/* w ww.ja v a 2 s . com*/ long s = System.currentTimeMillis(); final AtomicInteger ai = new AtomicInteger(0); List<Future<Event>> results = new ArrayList<Future<Event>>(); for (final Event event : events) { Future<Event> future = executorService.submit(new Callable<Event>() { @Override public Event call() { ai.incrementAndGet(); return intercept(event); } }); results.add(future); } // List<Event> out = Lists.newArrayList(); for (Future<Event> future : results) { Event event = null; try { event = future.get(); // // out.add(event); // if (event != null) { // out.add(event); // } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } long e = System.currentTimeMillis(); logger.info("rules:{}??{}", Thread.activeCount(), ai.intValue()); logger.info("rules:???{}", ai.intValue() / (e - s) / 1000); logger.info("rules:???{}", events.size() / (e - s) / 1000); return events; // return out; }
From source file:org.apache.hadoop.hbase.master.TestMasterOperationsForRegionReplicas.java
private void validateNumberOfRowsInMeta(final TableName table, int numRegions, Connection connection) throws IOException { assert (ADMIN.tableExists(table)); final AtomicInteger count = new AtomicInteger(); Visitor visitor = new Visitor() { @Override/* w ww . ja va 2 s . c o m*/ public boolean visit(Result r) throws IOException { if (HRegionInfo.getHRegionInfo(r).getTable().equals(table)) count.incrementAndGet(); return true; } }; MetaTableAccessor.fullScanRegions(connection, visitor); assert (count.get() == numRegions); }
From source file:com.spectralogic.ds3client.metadata.MetadataReceivedListenerImpl_Test.java
@Test public void testGettingMetadataFailureHandlerWindows() throws IOException, InterruptedException { Assume.assumeTrue(Platform.isWindows()); try {/*from w ww. j a v a2 s . com*/ final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String fileName = "Gracie.txt"; final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName)); try { // get permissions final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder(); fileMapper.put(filePath.toString(), filePath); final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build()) .getMetadataValue(filePath.toString()); FileUtils.deleteDirectory(tempDirectory.toFile()); // put old permissions back final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile)); final AtomicInteger numTimesFailureHandlerCalled = new AtomicInteger(0); new MetadataReceivedListenerImpl(tempDirectory.toString(), new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { numTimesFailureHandlerCalled.incrementAndGet(); assertEquals(FailureEvent.FailureActivity.RestoringMetadata, failureEvent.doingWhat()); } }, "localhost").metadataReceived(fileName, metadata); assertEquals(1, numTimesFailureHandlerCalled.get()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } } catch (final Throwable t) { fail("Throwing exceptions from metadata est verbotten"); } }
From source file:com.joyent.manta.client.jobs.MantaClientJobIT.java
@Test public void canListOutputsForJobAsStreams() throws IOException, InterruptedException { String path1 = String.format("%s/%s", testPathPrefix, UUID.randomUUID()); mantaClient.put(path1, TEST_DATA);/*from w ww . jav a2 s .c o m*/ String path2 = String.format("%s/%s", testPathPrefix, UUID.randomUUID()); mantaClient.put(path2, TEST_DATA); final MantaJob job = buildJob(); final UUID jobId = mantaClient.createJob(job); List<String> inputs = new ArrayList<>(); inputs.add(path1); inputs.add(path2); mantaClient.addJobInputs(jobId, inputs.iterator()); Assert.assertTrue(mantaClient.endJobInput(jobId)); awaitJobCompletion(jobId); final AtomicInteger count = new AtomicInteger(0); mantaClient.getJobOutputsAsStreams(jobId).forEach(o -> { count.incrementAndGet(); try { String content = IOUtils.toString(o, Charset.defaultCharset()); Assert.assertEquals(content, TEST_DATA); } catch (IOException e) { throw new UncheckedIOException(e); } }); Assert.assertEquals(count.get(), 2, "Missing both outputs"); }
From source file:com.joyent.manta.client.jobs.MantaClientJobIT.java
@Test public void canListOutputsForJobAsStrings() throws IOException, InterruptedException { String path1 = String.format("%s/%s", testPathPrefix, UUID.randomUUID()); mantaClient.put(path1, TEST_DATA);/*from w ww .j a va 2 s .c o m*/ String path2 = String.format("%s/%s", testPathPrefix, UUID.randomUUID()); mantaClient.put(path2, TEST_DATA); final MantaJob job = buildJob(); final UUID jobId = mantaClient.createJob(job); List<String> inputs = new ArrayList<>(); inputs.add(path1); inputs.add(path2); mantaClient.addJobInputs(jobId, inputs.iterator()); Assert.assertTrue(mantaClient.endJobInput(jobId)); awaitJobCompletion(jobId); final AtomicInteger count = new AtomicInteger(0); mantaClient.getJobOutputsAsStrings(jobId).forEach(content -> { count.incrementAndGet(); Assert.assertEquals(content, TEST_DATA); }); Assert.assertEquals(count.get(), 2, "Missing both outputs"); }
From source file:com.spectralogic.ds3client.metadata.MetadataReceivedListenerImpl_Test.java
@Test public void testGettingMetadataFailureHandler() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); try {/*from w w w . ja v a 2s . c o m*/ final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String fileName = "Gracie.txt"; final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName)); try { // set permissions if (!Platform.isWindows()) { final PosixFileAttributes attributes = Files.readAttributes(filePath, PosixFileAttributes.class); final Set<PosixFilePermission> permissions = attributes.permissions(); permissions.clear(); permissions.add(PosixFilePermission.OWNER_READ); permissions.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(filePath, permissions); } // get permissions final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder(); fileMapper.put(filePath.toString(), filePath); final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build()) .getMetadataValue(filePath.toString()); FileUtils.deleteDirectory(tempDirectory.toFile()); // put old permissions back final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile)); final AtomicInteger numTimesFailureHandlerCalled = new AtomicInteger(0); new MetadataReceivedListenerImpl(tempDirectory.toString(), new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { numTimesFailureHandlerCalled.incrementAndGet(); assertEquals(FailureEvent.FailureActivity.RestoringMetadata, failureEvent.doingWhat()); } }, "localhost").metadataReceived(fileName, metadata); assertEquals(1, numTimesFailureHandlerCalled.get()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } } catch (final Throwable t) { fail("Throwing exceptions from metadata est verbotten"); } }
From source file:com.taobao.pushit.server.listener.ConnectionNumberListener.java
/** * , //ww w .j a va2s . co m */ public void onConnectionCreated(Connection conn) { // IP String remoteIp = this.getRemoteIp(conn); try { // IPserver, AtomicInteger connNum = this.connectionIpNumMap.get(remoteIp); if (connNum == null) { AtomicInteger newConnNum = new AtomicInteger(0); AtomicInteger oldConnNum = this.connectionIpNumMap.putIfAbsent(remoteIp, newConnNum); if (oldConnNum != null) { connNum = oldConnNum; } else { connNum = newConnNum; } } connNum.incrementAndGet(); // , if (isOverflow || connNum.get() > this.connThreshold) { // log.warn("pushit-server, , :" + connNum.get() + ",:" + this.connThreshold); conn.close(false); } } catch (NotifyRemotingException e) { log.error(", remoteIp=" + remoteIp, e); } catch (Exception e) { log.error(", remoteIp=" + remoteIp, e); } }
From source file:org.atemsource.atem.utility.view.ViewBuilderTest.java
@Test public void testRemoveAndIncludePrimitives() { EntityType<EntityA> entityType = entityTypeRepository.getEntityType(EntityA.class); ViewBuilder viewBuilder = factory.create(entityType); viewBuilder.includePrimitives(false); viewBuilder.remove("intP"); View view = viewBuilder.create(); final Attribute intPAttribute = entityType.getAttribute("intP"); final AtomicInteger count = new AtomicInteger(); final ViewVisitor mockViewVisitor = new ViewVisitor<Object>() { @Override//from w w w . j a v a2s . com public void visit(Object context, Attribute attribute) { if (attribute == intPAttribute) { Assert.fail("intP was removed"); } else if (attribute.getTargetType() instanceof PrimitiveType<?> && attribute instanceof SingleAttribute<?>) { count.incrementAndGet(); } else { Assert.fail("not a single primitive " + attribute.getCode()); } } @Override public void visit(Object context, Attribute attribute, Visitor<Object> visitor) { Assert.fail("not a primitive " + attribute.getCode()); } @Override public void visitSubView(Object context, View view, Visitor<Object> subViewVisitor) { } @Override public void visitSuperView(Object context, View view, Visitor<Object> superViewVisitor) { } }; HierachyVisitor.visit(view, mockViewVisitor, null); Assert.assertTrue(count.intValue() > 2); }
From source file:com.neoteric.starter.metrics.report.elastic.ElasticsearchReporter.java
private HttpURLConnection writeJsonMetricAndRecreateConnectionIfNeeded(JsonMetric jsonMetric, HttpURLConnection connection, AtomicInteger entriesWritten) throws IOException { writeJsonMetric(jsonMetric, writer, connection.getOutputStream()); return createNewConnectionIfBulkSizeReached(connection, entriesWritten.incrementAndGet()); }