List of usage examples for java.util.concurrent.atomic AtomicInteger get
public final int get()
From source file:no.difi.sdp.client.asice.signature.CreateSignatureTest.java
@Test public void multithreaded_signing() throws Exception { List<Thread> threads = new ArrayList<Thread>(); final AtomicInteger fails = new AtomicInteger(0); for (int i = 0; i < 50; i++) { Thread t = new Thread() { @Override/* www.j a va 2 s . c om*/ public void run() { for (int j = 0; j < 20; j++) { Signature signature = sut.createSignature(noekkelpar, files); if (!verify_signature(signature)) { fails.incrementAndGet(); } if (fails.get() > 0) { break; } } } }; threads.add(t); t.start(); } for (Thread t : threads) { t.join(); } if (fails.get() > 0) { fail("Signature validation failed"); } }
From source file:cf.spring.servicebroker.ServiceBrokerTest.java
private void doProvisionTest(ProvisionBody provisionBody) throws IOException { final AtomicInteger provisionCounter = context.getBean("provisionCounter", AtomicInteger.class); provisionCounter.set(0);/*from w ww. jav a2 s. com*/ // Do provision final HttpUriRequest provisionRequest = RequestBuilder.put().setUri(instanceUri) .setEntity(new StringEntity(mapper.writeValueAsString(provisionBody), ContentType.APPLICATION_JSON)) .build(); final CloseableHttpResponse provisionResponse = client.execute(provisionRequest); assertEquals(provisionResponse.getStatusLine().getStatusCode(), 201); assertEquals(provisionCounter.get(), 1); final JsonNode provisionResponseJson = mapper.readTree(provisionResponse.getEntity().getContent()); assertTrue(provisionResponseJson.has("dashboard_url")); assertEquals(provisionResponseJson.get("dashboard_url").asText(), DASHBOARD_URL); }
From source file:com.android.tools.idea.editors.theme.ThemeEditorUtilsTest.java
public void testResourceResolverVisitor() { myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v14.xml", "res/values-v14/styles.xml"); myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v19.xml", "res/values-v19/styles.xml"); myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v21.xml", "res/values-v21/styles.xml"); final AtomicInteger visitedRepos = new AtomicInteger(0); // With only one source set, this should be called just once. ThemeEditorUtils.acceptResourceResolverVisitor(myFacet, new ThemeEditorUtils.ResourceFolderVisitor() { @Override// w w w.j a va 2s . c om public void visitResourceFolder(@NotNull LocalResourceRepository resources, String moduleName, @NotNull String variantName, boolean isSelected) { assertEquals("main", variantName); visitedRepos.incrementAndGet(); } }); assertEquals(1, visitedRepos.get()); // TODO: Test variants }
From source file:io.fabric8.msg.jnatsd.TestProtocol.java
@Test public void testUnsubscribe() throws Exception { final Channel<Boolean> ch = new Channel<Boolean>(); final AtomicInteger count = new AtomicInteger(0); final int max = 20; connectionFactory.setReconnectAllowed(false); try (Connection c = connectionFactory.createConnection()) { try (final AsyncSubscription s = c.subscribeAsync("foo", new MessageHandler() { @Override/*from www.j ava2s . c o m*/ public void onMessage(Message m) { count.incrementAndGet(); if (count.get() == max) { try { m.getSubscription().unsubscribe(); assertFalse(m.getSubscription().isValid()); } catch (Exception e) { fail("Unsubscribe failed with err: " + e.getMessage()); } ch.add(true); } } })) { for (int i = 0; i < max; i++) { c.publish("foo", null, (byte[]) null); } sleep(100); c.flush(); if (s.isValid()) { assertTrue("Test complete signal not received", ch.get(5, TimeUnit.SECONDS)); assertFalse(s.isValid()); } assertEquals(max, count.get()); } } }
From source file:com.github.gdrouet.scannerbenchmark.JmhBenchmark.java
/** * <p>/*w w w . j a v a 2 s . c o m*/ * Looking for type annotated with an annotation with annotation-detector. * </p> * * @throws Exception if test fails */ @Benchmark public void scanAnnotatedTypeWithAnnotationDetector() throws Exception { final AtomicInteger count = new AtomicInteger(0); final AnnotationDetector.TypeReporter typeReporter = new AnnotationDetector.TypeReporter() { @Override public void reportTypeAnnotation(final Class<? extends Annotation> annotation, final String className) { count.incrementAndGet(); } @SuppressWarnings("unchecked") @Override public Class<? extends Annotation>[] annotations() { return new Class[] { ANNOTATION }; } }; final AnnotationDetector cf = new AnnotationDetector(typeReporter); cf.detect(PACKAGE); LOGGER.info("{} classes annotated with {} retrieved with Annotation-Detector", count.get(), ANNOTATION.getName()); }
From source file:dk.statsbiblioteket.util.JobControllerTest.java
public void testPopAll() throws Exception { final int JOBS = 10; final AtomicInteger counter = new AtomicInteger(0); JobController<Long> controller = new JobController<Long>(10) { @Override//from w ww. j a va2s . c o m protected void afterExecute(Future<Long> finished) { counter.incrementAndGet(); } }; for (int i = 0; i < JOBS; i++) { synchronized (Thread.currentThread()) { Thread.currentThread().wait(10); } controller.submit(new Shout(50)); } int all = controller.popAll().size(); assertEquals("The total pops should be correct", 10, all); assertEquals("The callback count should be correct", 10, counter.get()); }
From source file:edu.msu.cme.rdp.kmer.cli.KmerCoverage.java
public void printCovereage(OutputStream coverage_out, OutputStream abundance_out) throws IOException { adjustCount();/*ww w .j av a 2s .c o m*/ // print out the weighted kmer coverage // we found mean coverage matched the previous biological observation PrintStream coverage_outStream = new PrintStream(coverage_out); coverage_outStream.println("#total reads: " + totalReads.intValue()); coverage_outStream.println("#use mean_cov to adjust the contig abundance, not median_cov "); coverage_outStream.println("#seqid\tmean_cov\tmedian_cov\ttotal_pos\tcovered_pos\tcovered_ratio"); for (Contig contig : contigMap.values()) { ArrayList<Double> counts = new ArrayList<Double>(); int coveredPos = 0; for (int pos = 0; pos < contig.coverage.length; pos++) { if (contig.coverage[pos] > 0) { coveredPos++; } counts.add(contig.coverage[pos]); } if (coveredPos > 0) { coverage_outStream.println(contig.name + "\t" + String.format(dformat, StdevCal.calMean(counts)) + "\t" + String.format(dformat, (StdevCal.calMedian(counts))) + "\t" + counts.size() + "\t" + coveredPos + "\t" + String.format(dformat, (double) coveredPos / (double) contig.coverage.length)); } else { // no coverage coverage_outStream.println( contig.name + "\t" + 0 + "\t" + 0 + "\t" + contig.coverage.length + "\t" + 0 + "\t" + 0); } } coverage_outStream.close(); // print kmer abundance HashMap<Integer, Integer> abundanceCountMap = new HashMap<Integer, Integer>(); // the frequeny of the kmer abundance PrintStream abundance_outStream = new PrintStream(abundance_out); // need to merge the counts from forward and reverse together. HashSet<Kmer> kmerSet = new HashSet<Kmer>(); kmerSet.addAll(kmerMaps[0].keySet()); for (Kmer kmer : kmerSet) { AtomicInteger abundance = kmerMaps[0].get(kmer).count; String reverseKmerStr = IUBUtilities.reverseComplement(kmer.decodeLong(kmer.getLongKmers())); Kmer reverseKmer = (new NuclKmerGenerator(reverseKmerStr, this.kmerSize)).next(); KmerAbund kmerAbund = kmerMaps[1].get(reverseKmer); if (kmerAbund != null) { abundance.addAndGet(kmerAbund.count.get()); } Integer count = abundanceCountMap.get(abundance.get()); if (count == null) { abundanceCountMap.put(abundance.get(), 1); } else { abundanceCountMap.put(abundance.get(), count + 1); } } abundance_outStream.println("kmer_abundance\tfrequency"); for (Integer abundance : abundanceCountMap.keySet()) { abundance_outStream.println(abundance + "\t" + abundanceCountMap.get(abundance)); } abundance_outStream.close(); }
From source file:com.joyent.manta.client.MantaClientIT.java
@Test public final void testList() throws IOException { final String pathPrefix = String.format("%s/%s", testPathPrefix, UUID.randomUUID()); mantaClient.putDirectory(pathPrefix, null); mantaClient.put(String.format("%s/%s", pathPrefix, UUID.randomUUID()), ""); mantaClient.put(String.format("%s/%s", pathPrefix, UUID.randomUUID()), ""); final String subDir = pathPrefix + "/" + UUID.randomUUID().toString(); mantaClient.putDirectory(subDir, null); mantaClient.put(String.format("%s/%s", subDir, UUID.randomUUID()), ""); final Stream<MantaObject> objs = mantaClient.listObjects(pathPrefix); final AtomicInteger count = new AtomicInteger(0); objs.forEach(obj -> {//from w w w . j ava2s . com count.incrementAndGet(); Assert.assertTrue(obj.getPath().startsWith(testPathPrefix)); }); Assert.assertEquals(3, count.get()); }
From source file:com.spectralogic.ds3client.metadata.MetadataReceivedListenerImpl_Test.java
@Test public void testGettingMetadataFailureHandlerWindows() throws IOException, InterruptedException { Assume.assumeTrue(Platform.isWindows()); try {/* w ww . j a va 2 s . co 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 { // 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:dk.statsbiblioteket.util.JobControllerTest.java
public void TestAutoEmpty() throws InterruptedException { final int JOBS = 10; final AtomicInteger counter = new AtomicInteger(0); JobController<Long> controller = new JobController<Long>(10, true) { @Override/*from w w w.j a v a 2 s . c om*/ protected void afterExecute(Future<Long> finished) { counter.incrementAndGet(); } }; for (int i = 0; i < JOBS; i++) { controller.submit(new Shout(JOBS / 4)); synchronized (Thread.currentThread()) { Thread.currentThread().wait(JOBS / 10); } } synchronized (Thread.currentThread()) { Thread.currentThread().wait(JOBS / 4 + 1); } assertEquals("The auto removed count should be all the jobs", JOBS, counter.get()); assertEquals("The JobController should be empty", 0, controller.getTaskCount()); }