java.util.concurrent.atomic.AtomicLong

Here are the examples of the java api class java.util.concurrent.atomic.AtomicLong taken from open source projects.

1. CacheStatistics#reset()

View license
public static void reset() {
    _numHitsTotal = new AtomicLong(0);
    _numHitsMem = new AtomicLong(0);
    _numHitsFSBuff = new AtomicLong(0);
    _numHitsFS = new AtomicLong(0);
    _numHitsHDFS = new AtomicLong(0);
    _numWritesFSBuff = new AtomicLong(0);
    _numWritesFS = new AtomicLong(0);
    _numWritesHDFS = new AtomicLong(0);
    _ctimeAcquireR = new AtomicLong(0);
    _ctimeAcquireM = new AtomicLong(0);
    _ctimeRelease = new AtomicLong(0);
    _ctimeExport = new AtomicLong(0);
}

2. StatsTest#testNormalizesIllegalChars()

Project: commons
Source File: StatsTest.java
View license
@Test
public void testNormalizesIllegalChars() {
    AtomicLong colon = Stats.exportLong("a:b");
    AtomicLong plus = Stats.exportLong("b+c");
    AtomicLong hyphen = Stats.exportLong("c-d");
    AtomicLong slash = Stats.exportLong("d/f");
    colon.incrementAndGet();
    plus.incrementAndGet();
    hyphen.incrementAndGet();
    slash.incrementAndGet();
    assertCounter("a_b", 1);
    assertCounter("b_c", 1);
    assertCounter("c_d", 1);
    assertCounter("d_f", 1);
}

3. StatsTest#testSupportedSpecialChars()

Project: aurora
Source File: StatsTest.java
View license
@Test
public void testSupportedSpecialChars() {
    AtomicLong hyphen = Stats.exportLong("c-d");
    AtomicLong slash = Stats.exportLong("d/f");
    AtomicLong dot = Stats.exportLong("f.g");
    hyphen.incrementAndGet();
    slash.incrementAndGet();
    dot.incrementAndGet();
    assertCounter("c-d", 1);
    assertCounter("d/f", 1);
    assertCounter("f.g", 1);
}

4. StatsTest#testNormalizesSpace()

Project: aurora
Source File: StatsTest.java
View license
@Test
public void testNormalizesSpace() {
    AtomicLong leading = Stats.exportLong("  leading space");
    AtomicLong trailing = Stats.exportLong("trailing space   ");
    AtomicLong surround = Stats.exportLong("   surround space   ");
    leading.incrementAndGet();
    trailing.incrementAndGet();
    surround.incrementAndGet();
    assertCounter("__leading_space", 1);
    assertCounter("trailing_space___", 1);
    assertCounter("___surround_space___", 1);
}

5. StatsTest#testNormalizesSpace()

Project: commons
Source File: StatsTest.java
View license
@Test
public void testNormalizesSpace() {
    AtomicLong leading = Stats.exportLong("  leading space");
    AtomicLong trailing = Stats.exportLong("trailing space   ");
    AtomicLong surround = Stats.exportLong("   surround space   ");
    leading.incrementAndGet();
    trailing.incrementAndGet();
    surround.incrementAndGet();
    assertCounter("__leading_space", 1);
    assertCounter("trailing_space___", 1);
    assertCounter("___surround_space___", 1);
}

6. RateTest#testVariableRateAtomicLong()

Project: aurora
Source File: RateTest.java
View license
@Test
public void testVariableRateAtomicLong() throws Exception {
    AtomicLong value = new AtomicLong();
    Rate<AtomicLong> rate = Rate.of("test", value).withTicker(ticker).build();
    ticker.waitNanos(ONE_SEC);
    value.set(10);
    assertEquals(0d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(20);
    assertEquals(10d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(50);
    assertEquals(30d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(100);
    assertEquals(50d, rate.sample(), EPSILON);
    control.replay();
}

7. RateTest#testVariableRateAtomicLong()

Project: commons
Source File: RateTest.java
View license
@Test
public void testVariableRateAtomicLong() throws Exception {
    AtomicLong value = new AtomicLong();
    Rate<AtomicLong> rate = Rate.of("test", value).withTicker(ticker).build();
    ticker.waitNanos(ONE_SEC);
    value.set(10);
    assertEquals(0d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(20);
    assertEquals(10d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(50);
    assertEquals(30d, rate.sample(), EPSILON);
    ticker.waitNanos(ONE_SEC);
    value.set(100);
    assertEquals(50d, rate.sample(), EPSILON);
    control.replay();
}

8. TimedSupervisorTaskTest#setUp()

Project: eureka
Source File: TimedSupervisorTaskTest.java
View license
@Before
public void setUp() {
    scheduler = Executors.newScheduledThreadPool(4, new ThreadFactoryBuilder().setNameFormat("DiscoveryClient-%d").setDaemon(true).build());
    helperExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
    executor = new ThreadPoolExecutor(// corePoolSize
    1, // maxPoolSize
    3, // keepAliveTime
    0, TimeUnit.SECONDS, // use direct handoff
    new SynchronousQueue<Runnable>());
    testTaskStartCounter = new AtomicLong(0);
    testTaskSuccessfulCounter = new AtomicLong(0);
    testTaskInterruptedCounter = new AtomicLong(0);
    maxConcurrentTestTasks = new AtomicLong(0);
    testTaskCounter = new AtomicLong(0);
}

9. OrderedMetadataListUpdater#computeNewParent()

View license
/**
     * Helper function to iterate through a list and compute a new parent for the target task
     * based on the target parent's indent
     * @param list
     * @param targetTaskId
     * @param newIndent
     * @return
     */
private long computeNewParent(Filter filter, LIST list, long targetTaskId, int targetParentIndent) {
    final AtomicInteger desiredParentIndent = new AtomicInteger(targetParentIndent);
    final AtomicLong targetTask = new AtomicLong(targetTaskId);
    final AtomicLong lastPotentialParent = new AtomicLong(Task.NO_ID);
    final AtomicBoolean computedParent = new AtomicBoolean(false);
    iterateThroughList(filter, list, new OrderedListIterator() {

        @Override
        public void processTask(long taskId, Metadata metadata) {
            if (targetTask.get() == taskId) {
                computedParent.set(true);
            }
            int indent = metadata.getValue(indentProperty());
            if (!computedParent.get() && indent == desiredParentIndent.get()) {
                lastPotentialParent.set(taskId);
            }
        }
    });
    if (lastPotentialParent.get() == Task.NO_ID)
        return Task.NO_ID;
    return lastPotentialParent.get();
}

10. BootstrapCheckTests#testMaxNumberOfThreadsCheck()

View license
public void testMaxNumberOfThreadsCheck() {
    final int limit = 1 << 11;
    final AtomicLong maxNumberOfThreads = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapCheck.MaxNumberOfThreadsCheck check = new BootstrapCheck.MaxNumberOfThreadsCheck() {

        @Override
        long getMaxNumberOfThreads() {
            return maxNumberOfThreads.get();
        }
    };
    final RuntimeException e = expectThrows(RuntimeException.class, () -> BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck"));
    assertThat(e.getMessage(), containsString("max number of threads"));
    maxNumberOfThreads.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");
    // nothing should happen if current max number of threads is
    // not available
    maxNumberOfThreads.set(-1);
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");
}

11. BootstrapCheckTests#testMaxMapCountCheck()

View license
public void testMaxMapCountCheck() {
    final int limit = 1 << 18;
    final AtomicLong maxMapCount = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapCheck.MaxMapCountCheck check = new BootstrapCheck.MaxMapCountCheck() {

        @Override
        long getMaxMapCount() {
            return maxMapCount.get();
        }
    };
    RuntimeException e = expectThrows(RuntimeException.class, () -> BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxMapCountCheck"));
    assertThat(e.getMessage(), containsString("max virtual memory areas vm.max_map_count"));
    maxMapCount.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxMapCountCheck");
    // nothing should happen if current vm.max_map_count is not
    // available
    maxMapCount.set(-1);
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxMapCountCheck");
}

12. JavaMemCached#test()

Project: xmemcached
Source File: JavaMemCached.java
View license
public static void test(MemCachedClient memcachedClient, int length, int threads, int repeats, boolean print) throws Exception {
    memcachedClient.flushAll();
    AtomicLong miss = new AtomicLong(0);
    AtomicLong fail = new AtomicLong(0);
    AtomicLong hit = new AtomicLong(0);
    CyclicBarrier barrier = new CyclicBarrier(threads + 1);
    for (int i = 0; i < threads; i++) {
        new ReadWriteThread(memcachedClient, repeats, barrier, i * repeats, length, miss, fail, hit).start();
    }
    barrier.await();
    long start = System.nanoTime();
    barrier.await();
    if (print) {
        long duration = System.nanoTime() - start;
        long total = repeats * threads;
        printResult(length, threads, repeats, miss, fail, hit, duration, total);
    }
}

13. Spymemcached#test()

Project: xmemcached
Source File: Spymemcached.java
View license
public static void test(MemcachedClient memcachedClient, int length, int threads, int repeats, boolean print) throws Exception {
    memcachedClient.flush();
    AtomicLong miss = new AtomicLong(0);
    AtomicLong fail = new AtomicLong(0);
    AtomicLong hit = new AtomicLong(0);
    CyclicBarrier barrier = new CyclicBarrier(threads + 1);
    for (int i = 0; i < threads; i++) {
        new ReadWriteThread(memcachedClient, repeats, barrier, i * repeats, length, miss, fail, hit).start();
    }
    barrier.await();
    long start = System.nanoTime();
    barrier.await();
    if (print) {
        long duration = System.nanoTime() - start;
        long total = repeats * threads;
        printResult(length, threads, repeats, miss, fail, hit, duration, total);
    }
}

14. Xmemcached#test()

Project: xmemcached
Source File: Xmemcached.java
View license
public static void test(MemcachedClient memcachedClient, int length, int threads, int repeats, boolean print) throws Exception {
    memcachedClient.flushAll();
    AtomicLong miss = new AtomicLong(0);
    AtomicLong fail = new AtomicLong(0);
    AtomicLong hit = new AtomicLong(0);
    CyclicBarrier barrier = new CyclicBarrier(threads + 1);
    for (int i = 0; i < threads; i++) {
        new ReadWriteThread(memcachedClient, repeats, barrier, i * repeats, length, miss, fail, hit).start();
    }
    barrier.await();
    long start = System.nanoTime();
    barrier.await();
    if (print) {
        long duration = System.nanoTime() - start;
        long total = repeats * threads;
        printResult(length, threads, repeats, miss, fail, hit, duration, total);
    }
}

15. TimerWheelTest#shouldHandleMultipleTimersInDifferentTicks()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleMultipleTimersInDifferentTicks() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp1 = new AtomicLong(-1);
    final AtomicLong firedTimestamp2 = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 256);
    final Runnable task1 = () -> firedTimestamp1.set(wheel.clock().nanoTime());
    final Runnable task2 = () -> firedTimestamp2.set(wheel.clock().nanoTime());
    wheel.newTimeout(15, TimeUnit.MILLISECONDS, task1);
    wheel.newTimeout(23, TimeUnit.MILLISECONDS, task2);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(128));
    assertThat(firedTimestamp1.get(), is(TimeUnit.MILLISECONDS.toNanos(16)));
    assertThat(firedTimestamp2.get(), is(TimeUnit.MILLISECONDS.toNanos(24)));
}

16. TimerWheelTest#shouldHandleMultipleTimersInSameTickSameRound()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleMultipleTimersInSameTickSameRound() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp1 = new AtomicLong(-1);
    final AtomicLong firedTimestamp2 = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 8);
    final Runnable task1 = () -> firedTimestamp1.set(wheel.clock().nanoTime());
    final Runnable task2 = () -> firedTimestamp2.set(wheel.clock().nanoTime());
    wheel.newTimeout(15, TimeUnit.MILLISECONDS, task1);
    wheel.newTimeout(15, TimeUnit.MILLISECONDS, task2);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(128));
    assertThat(firedTimestamp1.get(), is(TimeUnit.MILLISECONDS.toNanos(16)));
    assertThat(firedTimestamp2.get(), is(TimeUnit.MILLISECONDS.toNanos(16)));
}

17. TimerWheelTest#shouldHandleMultipleTimersInSameTickDifferentRound()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleMultipleTimersInSameTickDifferentRound() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp1 = new AtomicLong(-1);
    final AtomicLong firedTimestamp2 = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 8);
    final Runnable task1 = () -> firedTimestamp1.set(wheel.clock().nanoTime());
    final Runnable task2 = () -> firedTimestamp2.set(wheel.clock().nanoTime());
    wheel.newTimeout(15, TimeUnit.MILLISECONDS, task1);
    wheel.newTimeout(23, TimeUnit.MILLISECONDS, task2);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(128));
    assertThat(firedTimestamp1.get(), is(TimeUnit.MILLISECONDS.toNanos(16)));
    assertThat(firedTimestamp2.get(), is(TimeUnit.MILLISECONDS.toNanos(24)));
}

18. RangeVisitor#visitInternal()

Project: atlasdb
Source File: RangeVisitor.java
View license
private long visitInternal(final Transaction t, final Visitor visitor, RangeRequest request, final MutableRange range) {
    final AtomicLong numVisited = new AtomicLong();
    boolean isEmpty = t.getRange(tableRef, request).batchAccept(range.getBatchSize(), new AbortingVisitor<List<RowResult<byte[]>>, RuntimeException>() {

        @Override
        public boolean visit(List<RowResult<byte[]>> batch) {
            visitor.visit(t, batch);
            if (batch.size() < range.getBatchSize()) {
                range.setStartRow(null);
            } else {
                byte[] lastRow = batch.get(batch.size() - 1).getRowName();
                range.setStartRow(RangeRequests.nextLexicographicName(lastRow));
            }
            numVisited.set(batch.size());
            return false;
        }
    });
    if (isEmpty) {
        range.setStartRow(null);
    }
    return numVisited.get();
}

19. TableTasks#estimateSize()

Project: atlasdb
Source File: TableTasks.java
View license
public static long estimateSize(Transaction t, TableReference table, final int batchSize, final Function<byte[], byte[]> uniformizer) {
    final AtomicLong estimate = new AtomicLong();
    t.getRange(table, RangeRequest.all()).batchAccept(batchSize, new AbortingVisitor<List<RowResult<byte[]>>, RuntimeException>() {

        @Override
        public boolean visit(List<RowResult<byte[]>> batch) {
            if (batch.size() < batchSize) {
                estimate.set(batch.size());
            } else {
                byte[] row = uniformizer.apply(batch.get(batchSize - 1).getRowName());
                estimate.set(BigInteger.valueOf(2).pow(row.length * 8).multiply(BigInteger.valueOf(batchSize)).divide(new BigInteger(1, row)).longValue());
            }
            return false;
        }
    });
    return estimate.get();
}

20. ConcurrentLinkedHashMap#recordRead()

View license
/**
   * Records a read in the buffer and return its write count.
   *
   * @param bufferIndex the index to the chosen read buffer
   * @param node the entry in the page replacement policy
   * @return the number of writes on the chosen read buffer
   */
long recordRead(int bufferIndex, Node<K, V> node) {
    // The location in the buffer is chosen in a racy fashion as the increment
    // is not atomic with the insertion. This means that concurrent reads can
    // overlap and overwrite one another, resulting in a lossy buffer.
    final AtomicLong counter = readBufferWriteCount[bufferIndex];
    final long writeCount = counter.get();
    counter.lazySet(writeCount + 1);
    final int index = (int) (writeCount & READ_BUFFER_INDEX_MASK);
    readBuffers[bufferIndex][index].lazySet(node);
    return writeCount;
}

21. ClusterTest#testSequentialEvent()

Project: copycat
Source File: ClusterTest.java
View license
/**
   * Tests submitting a sequential event.
   */
private void testSequentialEvent(int nodes) throws Throwable {
    createServers(nodes);
    AtomicLong count = new AtomicLong();
    AtomicLong index = new AtomicLong();
    CopycatClient client = createClient();
    client.onEvent("test",  message -> {
        threadAssertEquals(count.incrementAndGet(), 2L);
        threadAssertEquals(index.get(), message);
        resume();
    });
    client.submit(new TestEvent(true)).thenAccept( result -> {
        threadAssertNotNull(result);
        threadAssertEquals(count.incrementAndGet(), 1L);
        index.set(result);
        resume();
    });
    await(30000, 2);
}

22. TestStatsCollectorCoda#testMessagesPending()

Project: Dempsy
Source File: TestStatsCollectorCoda.java
View license
@Test
public void testMessagesPending() {
    assertEquals("none yet", 0L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_PENDING));
    assertEquals("none yet", 0L, stats.getMessagesPending());
    final AtomicLong count = new AtomicLong(0);
    StatsCollector.Gauge gauge = new StatsCollector.Gauge() {

        @Override
        public long value() {
            return count.get();
        }
    };
    stats.setMessagesPendingGauge(gauge);
    assertEquals("none yet", 0L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_PENDING));
    assertEquals("none yet", 0L, stats.getMessagesPending());
    count.set(10);
    assertEquals("final value", 10L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_PENDING));
    assertEquals("final value", 10L, stats.getMessagesPending());
}

23. TestStatsCollectorCoda#testMessagesOutPending()

Project: Dempsy
Source File: TestStatsCollectorCoda.java
View license
@Test
public void testMessagesOutPending() {
    assertEquals("none yet", 0L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_OUT_PENDING));
    assertEquals("none yet", 0L, stats.getMessagesPending());
    final AtomicLong count = new AtomicLong(0);
    StatsCollector.Gauge gauge = new StatsCollector.Gauge() {

        @Override
        public long value() {
            return count.get();
        }
    };
    stats.setMessagesOutPendingGauge(gauge);
    assertEquals("none yet", 0L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_OUT_PENDING));
    assertEquals("none yet", 0L, stats.getMessagesOutPending());
    count.set(10);
    assertEquals("final value", 10L, getStatValue(stats, StatsCollectorCoda.GAGE_MSG_OUT_PENDING));
    assertEquals("final value", 10L, stats.getMessagesOutPending());
}

24. PrioritizedRunnableTests#testGetAgeInMillis()

View license
// test unit conversion with a controlled clock
public void testGetAgeInMillis() throws Exception {
    AtomicLong time = new AtomicLong();
    PrioritizedRunnable runnable = new PrioritizedRunnable(Priority.NORMAL, time::get) {

        @Override
        public void run() {
        }
    };
    assertEquals(0, runnable.getAgeInMillis());
    int milliseconds = randomIntBetween(1, 256);
    time.addAndGet(TimeUnit.NANOSECONDS.convert(milliseconds, TimeUnit.MILLISECONDS));
    assertEquals(milliseconds, runnable.getAgeInMillis());
}

25. AckDeadlineRenewerTest#testAddOneMessage()

View license
@Test
public void testAddOneMessage() throws InterruptedException {
    EasyMock.reset(pubsub);
    final CountDownLatch firstLatch = new CountDownLatch(1);
    final CountDownLatch secondLatch = new CountDownLatch(1);
    final AtomicLong firstRenewal = new AtomicLong();
    final AtomicLong secondRenewal = new AtomicLong();
    EasyMock.expect(pubsub.modifyAckDeadlineAsync(SUBSCRIPTION1, MIN_DEADLINE_MILLIS, TimeUnit.MILLISECONDS, ImmutableList.of(ACK_ID1))).andAnswer(createAnswer(firstLatch, firstRenewal));
    EasyMock.expect(pubsub.modifyAckDeadlineAsync(SUBSCRIPTION1, MIN_DEADLINE_MILLIS, TimeUnit.MILLISECONDS, ImmutableList.of(ACK_ID1))).andAnswer(createAnswer(secondLatch, secondRenewal));
    EasyMock.replay(pubsub);
    long addTime = System.currentTimeMillis();
    ackDeadlineRenewer.add(SUBSCRIPTION1, ACK_ID1);
    firstLatch.await();
    assertTrue(firstRenewal.get() < (addTime + MIN_DEADLINE_MILLIS));
    secondLatch.await();
    assertTrue(secondRenewal.get() < (firstRenewal.get() + MIN_DEADLINE_MILLIS));
}

26. PointCacheTest#caclDbSize()

Project: geogig
Source File: PointCacheTest.java
View license
private long caclDbSize() {
    final File repoDir = new File(tmpFolder.getRoot(), ".geogig");
    final AtomicLong sizeContainer = new AtomicLong();
    repoDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(final File file) {
            if (file.isFile()) {
                long length = file.length();
                sizeContainer.addAndGet(length);
            } else {
                file.listFiles(this);
            }
            return true;
        }
    });
    return sizeContainer.get();
}

27. AddressRequestIdGenerator#getNextRequestId()

View license
/**
   * Get the next request id for a given destination.  Thread-safe.
   *
   * @param address Address of the worker (consistent during a superstep)
   * @return Valid request id
   */
public Long getNextRequestId(InetSocketAddress address) {
    AtomicLong requestGenerator = addressRequestGeneratorMap.get(address);
    if (requestGenerator == null) {
        requestGenerator = new AtomicLong(0);
        AtomicLong oldRequestGenerator = addressRequestGeneratorMap.putIfAbsent(address, requestGenerator);
        if (oldRequestGenerator != null) {
            requestGenerator = oldRequestGenerator;
        }
    }
    return requestGenerator.getAndIncrement();
}

28. DefaultMetricsCollector#gauge()

View license
@Override
public void gauge(String metricName, int value, String... tags) {
    AtomicLong gauge = gauges.get(metricName);
    if (gauge == null) {
        final AtomicLong newValue = new AtomicLong();
        if (gauges.putIfAbsent(metricName, newValue) == null) {
            // first to set the value, need to register the metric
            metrics.register(metricName, new Gauge<Long>() {

                @Override
                public Long getValue() {
                    return newValue.get();
                }
            });
            gauge = newValue;
        } else {
            // someone else set it first
            gauge = gauges.get(metricName);
        }
    }
    gauge.set(value);
}

29. SimpleStatsTest#meterResetAndCount()

Project: jackrabbit-oak
Source File: SimpleStatsTest.java
View license
@Test
public void meterResetAndCount() throws Exception {
    AtomicLong counter = new AtomicLong();
    MeterStats stats = new SimpleStats(counter, SimpleStats.Type.METER);
    stats.mark();
    assertEquals(1, stats.getCount());
    stats.mark();
    assertEquals(2, stats.getCount());
    stats.mark(5);
    assertEquals(7, stats.getCount());
    counter.set(0);
    assertEquals(7, stats.getCount());
}

30. SimpleBolt#execute()

Project: jstorm
Source File: SimpleBolt.java
View license
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    BatchId id = (BatchId) input.getValue(0);
    Long value = input.getLong(1);
    AtomicLong counter = counters.get(id);
    if (counter == null) {
        counter = new AtomicLong(0);
        counters.put(id, counter);
    }
    counter.addAndGet(value);
}

31. LongSumMerger#merge()

Project: jstorm
Source File: LongSumMerger.java
View license
@Override
public AtomicLong merge(Collection<AtomicLong> objs, AtomicLong unflushed, Object... others) {
    AtomicLong ret = new AtomicLong(0);
    if (unflushed != null) {
        ret.addAndGet(unflushed.get());
    }
    for (AtomicLong item : objs) {
        if (item == null) {
            continue;
        }
        ret.addAndGet(item.get());
    }
    return ret;
}

32. CountBolt#execute()

Project: jstorm
Source File: CountBolt.java
View license
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    BatchId id = (BatchId) input.getValue(0);
    AtomicLong counter = counters.get(id);
    if (counter == null) {
        counter = new AtomicLong(0);
        counters.put(id, counter);
    }
    counter.incrementAndGet();
}

33. DBBolt#commit()

Project: jstorm
Source File: DBBolt.java
View license
@Override
public byte[] commit(BatchId id) throws FailedException {
    AtomicLong count = (AtomicLong) counters.remove(id);
    if (count == null) {
        count = new AtomicLong(0);
    }
    AtomicLong sum = (AtomicLong) sums.remove(id);
    if (sum == null) {
        sum = new AtomicLong(0);
    }
    CommitedValue commitedValue = new CommitedValue(count, sum);
    try {
        commitedValue.commit();
        return Utils.serialize(commitedValue);
    } catch (Exception e) {
        LOG.error("Failed to commit " + commitedValue, e);
        throw new FailedException(e);
    }
}

34. LuceneIndexProviderTest#assertStorageLocationUnchangedAfterRestart()

View license
@Override
protected void assertStorageLocationUnchangedAfterRestart() throws Exception {
    // register the total size and last modified timestamp of the place where indexes are stored for the default provider..
    File indexesDir1 = new File("target/persistent_repository/indexes/lucene_primary/default/ref1");
    assertTrue(indexesDir1.exists() && indexesDir1.isDirectory() && indexesDir1.canRead());
    long sizeDir1 = FileUtil.size(indexesDir1.getPath());
    final AtomicLong lastModifiedDateDir1 = lastModifiedFileTime(indexesDir1, "_0.*");
    File indexesDir2 = new File("target/persistent_repository/indexes/lucene_primary/default/ref2");
    assertTrue(indexesDir2.exists() && indexesDir2.isDirectory() && indexesDir2.canRead());
    long sizeDir2 = FileUtil.size(indexesDir1.getPath());
    final AtomicLong lastModifiedDateDir2 = lastModifiedFileTime(indexesDir2, "_0.*");
    startRepository();
    printMessage("Repository restart complete");
    // and now check that the storage folder is unchanged
    assertEquals(sizeDir1, FileUtil.size(indexesDir1.getPath()));
    assertEquals(lastModifiedDateDir1.get(), lastModifiedFileTime(indexesDir1, "_0.*").get());
    assertEquals(sizeDir2, FileUtil.size(indexesDir2.getPath()));
    assertEquals(lastModifiedDateDir2.get(), lastModifiedFileTime(indexesDir2, "_0.*").get());
}

35. FileUtil#size()

Project: modeshape
Source File: FileUtil.java
View license
/**
     * Determines the size (in bytes) of the file or directory at the given path.
     *
     * @param filePath the path of the file; may not be {@code null}
     * @return the size in bytes of the file or the total computed size of the folder. If the given path is not a valid file or
     * folder, this will return 0.
     * @throws IOException if anything unexpected fails.
     */
public static long size(String filePath) throws IOException {
    CheckArg.isNotEmpty(filePath, "filePath");
    File file = new File(filePath);
    if (!file.exists()) {
        return 0;
    }
    if (file.isFile()) {
        return file.length();
    }
    final AtomicLong size = new AtomicLong();
    Files.walkFileTree(Paths.get(filePath), new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            size.addAndGet(attrs.size());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) {
            return FileVisitResult.CONTINUE;
        }
    });
    return size.get();
}

36. BlockingConnection#getReceiveBuffer()

Project: mqtt-client
Source File: BlockingConnection.java
View license
public long getReceiveBuffer() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final AtomicLong result = new AtomicLong();
    next.getDispatchQueue().execute(new Runnable() {

        public void run() {
            try {
                result.set(next.getReceiveBuffer());
            } finally {
                done.countDown();
            }
        }
    });
    done.await();
    return result.get();
}

37. NodeIdGenerator#getNextNodeId()

Project: pig
Source File: NodeIdGenerator.java
View license
/**
     * Returns the next ID to be used for the current Thread.
     * 
     * @param scope
     * @return
     */
public long getNextNodeId(final String scope) {
    // ThreadLocal usage protects us from having the same HashMap instance
    // being used by several threads, so we can use it without synchronized
    // blocks and still be thread-safe.
    Map<String, AtomicLong> map = scopeToIdMap.get();
    // the concurrent properties of the AtomicLong are useless here but
    // since it cost less to use such an object rather than created a
    // Long object instance each time we increment a counter ...
    AtomicLong l = map.get(scope);
    if (l == null)
        map.put(scope, l = new AtomicLong());
    return l.getAndIncrement();
}

38. ActionsTest#testToFunc0()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc0() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action0 action = new Action0() {

        @Override
        public void call() {
            value.set(0);
        }
    };
    assertNull(Actions.toFunc(action).call());
    assertEquals(0, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call());
    assertEquals(0, value.get());
}

39. ActionsTest#testToFunc1()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc1() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action1<Integer> action = new Action1<Integer>() {

        @Override
        public void call(Integer t1) {
            value.set(t1);
        }
    };
    assertNull(Actions.toFunc(action).call(1));
    assertEquals(1, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1));
    assertEquals(1, value.get());
}

40. ActionsTest#testToFunc2()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc2() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action2<Integer, Integer> action = new Action2<Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2) {
            value.set(t1 | t2);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2));
    assertNull(Actions.toFunc(action).call(1, 2));
    assertEquals(3, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2));
    assertEquals(3, value.get());
}

41. ActionsTest#testToFunc3()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc3() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action3<Integer, Integer, Integer> action = new Action3<Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3) {
            value.set(t1 | t2 | t3);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4));
    assertEquals(7, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4));
    assertEquals(7, value.get());
}

42. ActionsTest#testToFunc4()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc4() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action4<Integer, Integer, Integer, Integer> action = new Action4<Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4) {
            value.set(t1 | t2 | t3 | t4);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8));
    assertEquals(15, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8));
    assertEquals(15, value.get());
}

43. ActionsTest#testToFunc5()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc5() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action5<Integer, Integer, Integer, Integer, Integer> action = new Action5<Integer, Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5) {
            value.set(t1 | t2 | t3 | t4 | t5);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8, 16));
    assertEquals(31, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8, 16));
    assertEquals(31, value.get());
}

44. ActionsTest#testToFunc6()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc6() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action6<Integer, Integer, Integer, Integer, Integer, Integer> action = new Action6<Integer, Integer, Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6) {
            value.set(t1 | t2 | t3 | t4 | t5 | t6);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8, 16, 32));
    assertEquals(63, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8, 16, 32));
    assertEquals(63, value.get());
}

45. ActionsTest#testToFunc7()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc7() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action7<Integer, Integer, Integer, Integer, Integer, Integer, Integer> action = new Action7<Integer, Integer, Integer, Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7) {
            value.set(t1 | t2 | t3 | t4 | t5 | t6 | t7);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8, 16, 32, 64));
    assertEquals(127, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8, 16, 32, 64));
    assertEquals(127, value.get());
}

46. ActionsTest#testToFunc8()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc8() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> action = new Action8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8) {
            value.set(t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8, 16, 32, 64, 128));
    assertEquals(255, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8, 16, 32, 64, 128));
    assertEquals(255, value.get());
}

47. ActionsTest#testToFunc9()

Project: RxJava
Source File: ActionsTest.java
View license
@Test
public void testToFunc9() {
    final AtomicLong value = new AtomicLong(-1L);
    final Action9<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> action = new Action9<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer>() {

        @Override
        public void call(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8, Integer t9) {
            value.set(t1 | t2 | t3 | t4 | t5 | t6 | t7 | t8 | t9);
        }
    };
    assertNull(Actions.toFunc(action).call(1, 2, 4, 8, 16, 32, 64, 128, 256));
    assertEquals(511, value.get());
    value.set(-1L);
    assertEquals((Integer) 0, Actions.toFunc(action, 0).call(1, 2, 4, 8, 16, 32, 64, 128, 256));
    assertEquals(511, value.get());
}

48. ProgressLoggerTest#log_at_fixed_intervals()

Project: sonarqube
Source File: ProgressLoggerTest.java
View license
@Test(timeout = 1000L)
public void log_at_fixed_intervals() throws Exception {
    Logger logger = mock(Logger.class);
    AtomicLong counter = new AtomicLong(42L);
    ProgressLogger progress = new ProgressLogger("ProgressLoggerTest", counter, logger);
    progress.setPeriodMs(1L);
    progress.start();
    Thread.sleep(80L);
    progress.stop();
    verify(logger, atLeast(1)).info(startsWith("42 rows processed"));
    // ability to manual log, generally final status
    counter.incrementAndGet();
    progress.log();
    verify(logger).info(startsWith("43 rows processed"));
}

49. LongStreamExTest#testPeekFirst()

Project: streamex
Source File: LongStreamExTest.java
View license
@Test
public void testPeekFirst() {
    long[] input = { 1, 10, 100, 1000 };
    AtomicLong firstElement = new AtomicLong();
    assertArrayEquals(new long[] { 10, 100, 1000 }, LongStreamEx.of(input).peekFirst(firstElement::set).skip(1).toArray());
    assertEquals(1, firstElement.get());
    assertArrayEquals(new long[] { 10, 100, 1000 }, LongStreamEx.of(input).skip(1).peekFirst(firstElement::set).toArray());
    assertEquals(10, firstElement.get());
    firstElement.set(-1);
    assertArrayEquals(new long[] {}, LongStreamEx.of(input).skip(4).peekFirst(firstElement::set).toArray());
    assertEquals(-1, firstElement.get());
}

50. DefaultMetricsCollector#gauge()

Project: tephra
Source File: DefaultMetricsCollector.java
View license
@Override
public void gauge(String metricName, int value, String... tags) {
    AtomicLong gauge = gauges.get(metricName);
    if (gauge == null) {
        final AtomicLong newValue = new AtomicLong();
        if (gauges.putIfAbsent(metricName, newValue) == null) {
            // first to set the value, need to register the metric
            metrics.register(metricName, new Gauge<Long>() {

                @Override
                public Long getValue() {
                    return newValue.get();
                }
            });
            gauge = newValue;
        } else {
            // someone else set it first
            gauge = gauges.get(metricName);
        }
    }
    gauge.set(value);
}

51. CorpusMerge#merge()

Project: word
Source File: CorpusMerge.java
View license
/**
     * ?????????????
     * @param source ????????
     * @param target ????
     * @throws IOException 
     */
public static void merge(String source, String target) throws IOException {
    final AtomicLong count = new AtomicLong();
    final AtomicLong lines = new AtomicLong();
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target), "utf-8"))) {
        Files.walkFileTree(Paths.get(source), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                LOGGER.info("?????" + file);
                try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile()), "utf-8"))) {
                    String line;
                    while ((line = reader.readLine()) != null) {
                        count.addAndGet(line.length());
                        lines.incrementAndGet();
                        writer.write(line + "\n");
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
    }
    LOGGER.info("??????" + lines.get());
    LOGGER.info("????????" + count.get());
}

52. TimerWheelTest#shouldBeAbleToScheduleTimerOnEdgeOfTick()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test(timeout = 1000)
public void shouldBeAbleToScheduleTimerOnEdgeOfTick() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 1024);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    wheel.newTimeout(5000, TimeUnit.MICROSECONDS, task);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> firedTimestamp.get() != -1);
    // this is the first tick after the timer, so it should be on this edge
    assertThat(firedTimestamp.get(), is(TimeUnit.MILLISECONDS.toNanos(6)));
}

53. TimerWheelTest#shouldHandleNonZeroStartTime()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test(timeout = 1000)
public void shouldHandleNonZeroStartTime() {
    controlTimestamp = TimeUnit.MILLISECONDS.toNanos(100);
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 1024);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    wheel.newTimeout(5000, TimeUnit.MICROSECONDS, task);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> firedTimestamp.get() != -1);
    // this is the first tick after the timer, so it should be on this edge
    // relative to start time
    assertThat(firedTimestamp.get(), is(TimeUnit.MILLISECONDS.toNanos(106)));
}

54. TimerWheelTest#shouldHandleNanoTimeUnitTimers()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleNanoTimeUnitTimers() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 1024);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    wheel.newTimeout(5000001, TimeUnit.NANOSECONDS, task);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> firedTimestamp.get() != -1);
    // this is the first tick after the timer, so it should be on this edge
    assertThat(firedTimestamp.get(), is(TimeUnit.MILLISECONDS.toNanos(6)));
}

55. TimerWheelTest#shouldHandleMultipleRounds()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleMultipleRounds() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 16);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    wheel.newTimeout(63, TimeUnit.MILLISECONDS, task);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> firedTimestamp.get() != -1);
    // this is the first tick after the timer, so it should be on this edge
    // relative to start time
    assertThat(firedTimestamp.get(), is(TimeUnit.MILLISECONDS.toNanos(64)));
}

56. TimerWheelTest#shouldBeAbleToCancelTimer()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldBeAbleToCancelTimer() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 256);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    final TimerWheel.Timer timeout = wheel.newTimeout(63, TimeUnit.MILLISECONDS, task);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(16));
    timeout.cancel();
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(128));
    assertThat(firedTimestamp.get(), is(-1L));
}

57. TimerWheelTest#shouldHandleExpiringTimersInPreviousTicks()

Project: Agrona
Source File: TimerWheelTest.java
View license
@Test
public void shouldHandleExpiringTimersInPreviousTicks() {
    controlTimestamp = 0;
    final AtomicLong firedTimestamp = new AtomicLong(-1);
    final TimerWheel wheel = new TimerWheel(this::getControlTimestamp, 1, TimeUnit.MILLISECONDS, 256);
    final Runnable task = () -> firedTimestamp.set(wheel.clock().nanoTime());
    wheel.newTimeout(15, TimeUnit.MILLISECONDS, task);
    controlTimestamp += TimeUnit.MILLISECONDS.toNanos(32);
    processTimersUntil(wheel, ONE_MS_OF_NS, () -> wheel.clock().nanoTime() > TimeUnit.MILLISECONDS.toNanos(128));
    // time of first expireTimers call
    assertThat(firedTimestamp.get(), is(TimeUnit.MILLISECONDS.toNanos(32)));
}

58. QuantileDigest#getMin()

Project: airlift
Source File: QuantileDigest.java
View license
public long getMin() {
    final AtomicLong chosen = new AtomicLong(min);
    postOrderTraversal(root, new Callback() {

        public boolean process(Node node) {
            if (node.weightedCount >= ZERO_WEIGHT_THRESHOLD) {
                chosen.set(node.getLowerBound());
                return false;
            }
            return true;
        }
    }, TraversalOrder.FORWARD);
    return Math.max(min, chosen.get());
}

59. QuantileDigest#getMax()

Project: airlift
Source File: QuantileDigest.java
View license
public long getMax() {
    final AtomicLong chosen = new AtomicLong(max);
    postOrderTraversal(root, new Callback() {

        public boolean process(Node node) {
            if (node.weightedCount >= ZERO_WEIGHT_THRESHOLD) {
                chosen.set(node.getUpperBound());
                return false;
            }
            return true;
        }
    }, TraversalOrder.REVERSE);
    return Math.min(max, chosen.get());
}

60. ConsistencyCheckerTool#checkConsistency()

Project: ambry
Source File: ConsistencyCheckerTool.java
View license
@Override
public boolean checkConsistency(String directoryForConsistencyCheck) throws Exception {
    File rootDir = new File(directoryForConsistencyCheck);
    logOutput("Root directory for Partition" + rootDir);
    ArrayList<String> replicaList = populateReplicaList(rootDir);
    logOutput("Replica List " + replicaList);
    ConcurrentHashMap<String, BlobStatus> blobIdToStatusMap = new ConcurrentHashMap<String, BlobStatus>();
    AtomicLong totalKeysProcessed = new AtomicLong(0);
    int replicaCount = replicaList.size();
    doCheck(rootDir.listFiles(), replicaList, blobIdToStatusMap, totalKeysProcessed);
    return populateOutput(totalKeysProcessed, blobIdToStatusMap, replicaCount, includeAcceptableInconsistentBlobs);
}

61. WorkerBackpressureThreadTest#testNormalEvent()

View license
@Test
public void testNormalEvent() throws Exception {
    Object trigger = new Object();
    AtomicLong workerData = new AtomicLong(0);
    WorkerBackpressureCallback callback = new WorkerBackpressureCallback() {

        @Override
        public void onEvent(Object obj) {
            ((AtomicLong) obj).getAndDecrement();
        }
    };
    WorkerBackpressureThread workerBackpressureThread = new WorkerBackpressureThread(trigger, workerData, callback);
    workerBackpressureThread.start();
    WorkerBackpressureThread.notifyBackpressureChecker(trigger);
    long start = System.currentTimeMillis();
    while (workerData.get() == 0) {
        assertTrue("Timeout", (System.currentTimeMillis() - start) < 1000);
        Thread.sleep(100);
    }
}

62. GtasksMetadataService#getRemoteSiblingId()

Project: astrid
Source File: GtasksMetadataService.java
View license
/**
     * Gets the remote id string of the previous sibling task
     * @param listId
     * @param gtasksMetadata
     * @return
     */
public String getRemoteSiblingId(String listId, Metadata gtasksMetadata) {
    final AtomicInteger indentToMatch = new AtomicInteger(gtasksMetadata.getValue(GtasksMetadata.INDENT).intValue());
    final AtomicLong parentToMatch = new AtomicLong(gtasksMetadata.getValue(GtasksMetadata.PARENT_TASK).longValue());
    final AtomicReference<String> sibling = new AtomicReference<String>();
    OrderedListIterator iterator = new OrderedListIterator() {

        @Override
        public void processTask(long taskId, Metadata metadata) {
            Task t = taskDao.fetch(taskId, Task.TITLE, Task.DELETION_DATE);
            if (t == null || t.isDeleted())
                return;
            int currIndent = metadata.getValue(GtasksMetadata.INDENT).intValue();
            long currParent = metadata.getValue(GtasksMetadata.PARENT_TASK);
            if (currIndent == indentToMatch.get() && currParent == parentToMatch.get()) {
                if (sibling.get() == null) {
                    sibling.set(metadata.getValue(GtasksMetadata.ID));
                }
            }
        }
    };
    this.iterateThroughList(listId, iterator, gtasksMetadata.getValue(GtasksMetadata.ORDER), true);
    return sibling.get();
}

63. AllRowsQueryTest#getAll()

Project: astyanax
Source File: AllRowsQueryTest.java
View license
@Test
public void getAll() throws Exception {
    AtomicLong counter = new AtomicLong(0);
    OperationResult<Rows<String, String>> rows = keyspace.prepareQuery(CF_ALL_ROWS).getAllRows().setConcurrencyLevel(2).setRowLimit(30).setExceptionCallback(//.withColumnRange(new RangeBuilder().setLimit(0).build())
    new ExceptionCallback() {

        @Override
        public boolean onException(ConnectionException e) {
            Assert.fail(e.getMessage());
            return true;
        }
    }).execute();
    for (Row<String, String> row : rows.getResult()) {
        counter.incrementAndGet();
        LOG.info("ROW: " + row.getKey() + " " + row.getColumns().size());
    }
    LOG.info("Read " + counter.get() + " keys");
    Assert.assertEquals(26, counter.get());
}

64. ThriftKeyspaceImplTest#getAll()

View license
@Test
public void getAll() {
    AtomicLong counter = new AtomicLong(0);
    try {
        OperationResult<Rows<String, String>> rows = keyspace.prepareQuery(CF_ALLROWS).getAllRows().setConcurrencyLevel(2).setRowLimit(10).setRepeatLastToken(false).withColumnRange(new RangeBuilder().setLimit(0).build()).setExceptionCallback(new ExceptionCallback() {

            @Override
            public boolean onException(ConnectionException e) {
                Assert.fail(e.getMessage());
                return true;
            }
        }).execute();
        for (Row<String, String> row : rows.getResult()) {
            counter.incrementAndGet();
            LOG.info("ROW: " + row.getKey() + " " + row.getColumns().size());
        }
        Assert.assertEquals(26, counter.get());
    } catch (ConnectionException e) {
        Assert.fail();
    }
}

65. TestSweepCommand#setup()

Project: atlasdb
Source File: TestSweepCommand.java
View license
@BeforeClass
public static void setup() throws Exception {
    sweepTimestamp = new AtomicLong();
    moduleFactory = new AtlasDbServicesFactory() {

        @Override
        public TestAtlasDbServices connect(ServicesConfigModule servicesConfigModule) {
            return DaggerTestAtlasDbServices.builder().servicesConfigModule(servicesConfigModule).testSweeperModule(TestSweeperModule.create(sweepTimestamp::get)).build();
        }
    };
}

66. AbstractTransaction#getNewBatchNumber()

Project: atlasdb
Source File: AbstractTransaction.java
View license
private long getNewBatchNumber(TableReference tableRef) {
    AtomicLong atomicLong = batchNumber.get(tableRef);
    if (atomicLong == null) {
        batchNumber.putIfAbsent(tableRef, new AtomicLong());
        atomicLong = batchNumber.get(tableRef);
    }
    long ret = atomicLong.getAndIncrement();
    if (ret >= getTimestamp()) {
        throw new IllegalStateException("There have been more writes to this temp table than " + "all other transactions combined");
    }
    return ret;
}

67. AbstractOperationStats#clearStats()

Project: atlasdb
Source File: AbstractOperationStats.java
View license
@Override
public synchronized void clearStats() {
    dSumTimeNanos = 0;
    dSumSquaredTimeNanos = 0;
    operationTimeNanos = 0;
    totalCalls = 0;
    maxCall = 0;
    minCall = Long.MAX_VALUE;
    for (AtomicLong al : underStatsMillis) {
        al.set(0);
    }
}

68. PubsubEventModule#provideEventBus()

Project: aurora
Source File: PubsubEventModule.java
View license
@Provides
@Singleton
EventBus provideEventBus(@AsyncExecutor Executor executor, StatsProvider statsProvider) {
    final AtomicLong subscriberExceptions = statsProvider.makeCounter(EXCEPTIONS_STAT);
    EventBus eventBus = new AsyncEventBus(executor, ( exception,  context) -> {
        subscriberExceptions.incrementAndGet();
        log.error("Failed to dispatch event to " + context.getSubscriberMethod() + ": " + exception, exception);
    });
    eventBus.register(new DeadEventHandler());
    return eventBus;
}

69. RowGarbageCollector#runOneIteration()

Project: aurora
Source File: RowGarbageCollector.java
View license
@VisibleForTesting
@Override
public void runOneIteration() {
    LOG.info("Scanning database tables for unreferenced rows.");
    final AtomicLong deletedCount = new AtomicLong();
    for (Class<? extends GarbageCollectedTableMapper> tableClass : TABLES) {
        storage.write((NoResult.Quiet)  storeProvider -> {
            try (SqlSession session = sessionFactory.openSession(true)) {
                GarbageCollectedTableMapper table = session.getMapper(tableClass);
                for (long rowId : table.selectAllRowIds()) {
                    try {
                        table.deleteRow(rowId);
                        deletedCount.incrementAndGet();
                    } catch (PersistenceException e) {
                    }
                }
            }
        });
    }
    LOG.info("Deleted " + deletedCount.get() + " unreferenced rows.");
}

70. TaskTimeoutTest#setUp()

Project: aurora
Source File: TaskTimeoutTest.java
View license
@Before
public void setUp() {
    executor = createMock(DelayExecutor.class);
    storageUtil = new StorageTestUtil(this);
    storageUtil.expectOperations();
    stateManager = createMock(StateManager.class);
    clock = new FakeClock();
    statsProvider = createMock(StatsProvider.class);
    timedOutTaskCounter = new AtomicLong();
    expect(statsProvider.makeCounter(TaskTimeout.TIMED_OUT_TASKS_COUNTER)).andReturn(timedOutTaskCounter);
}

71. AutoProfilerTest#simple()

Project: bazel
Source File: AutoProfilerTest.java
View license
@Test
public void simple() {
    final AtomicLong elapsedTime = new AtomicLong();
    ElapsedTimeReceiver receiver = new ElapsedTimeReceiver() {

        @Override
        public void accept(long elapsedTimeNanos) {
            elapsedTime.set(elapsedTimeNanos);
        }
    };
    try (AutoProfiler profiler = AutoProfiler.create(receiver)) {
        clock.advanceMillis(42);
    }
    assertThat(elapsedTime.get()).isEqualTo(42 * 1000 * 1000);
}

72. TestAuth#testSingleMessageAuth()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test an connection will authorize with a single message
     * to the server and a single response.
     */
@Test(timeout = 30000)
public void testSingleMessageAuth() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(AlwaysSucceedBookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    // should succeed
    connectAndWriteToBookie(clientConf, ledgerId);
    assertFalse(ledgerId.get() == -1);
    assertEquals("Should have entry", 1, entryCount(ledgerId.get(), bookieConf, clientConf));
}

73. TestAuth#testSingleMessageAuthFailure()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that when the bookie provider sends a failure message
     * the client will not be able to write
     */
@Test(timeout = 30000)
public void testSingleMessageAuthFailure() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(AlwaysFailBookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    try {
        // should fail
        connectAndWriteToBookie(clientConf, ledgerId);
        fail("Shouldn't get this far");
    } catch (BKException.BKUnauthorizedAccessException bke) {
    }
    assertFalse(ledgerId.get() == -1);
    assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
}

74. TestAuth#testMultiMessageAuth()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that authentication works when the providers
     * exchange multiple messages
     */
@Test(timeout = 30000)
public void testMultiMessageAuth() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(SucceedAfter3BookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    AtomicLong ledgerId = new AtomicLong(-1);
    startAndStoreBookie(bookieConf);
    // should succeed
    connectAndWriteToBookie(clientConf, ledgerId);
    assertFalse(ledgerId.get() == -1);
    assertEquals("Should have entry", 1, entryCount(ledgerId.get(), bookieConf, clientConf));
}

75. TestAuth#testMultiMessageAuthFailure()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that when the bookie provider sends a failure message
     * the client will not be able to write
     */
@Test(timeout = 30000)
public void testMultiMessageAuthFailure() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(FailAfter3BookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    try {
        // should fail
        connectAndWriteToBookie(clientConf, ledgerId);
        fail("Shouldn't get this far");
    } catch (BKException.BKUnauthorizedAccessException bke) {
    }
    assertFalse(ledgerId.get() == -1);
    assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
}

76. TestAuth#testDifferentPluginFailure()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that when the bookie and the client have a different
     * plugin configured, no messages will get through.
     */
@Test(timeout = 30000)
public void testDifferentPluginFailure() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(DifferentPluginBookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    try {
        // should fail
        connectAndWriteToBookie(clientConf, ledgerId);
        fail("Shouldn't get this far");
    } catch (BKException.BKUnauthorizedAccessException bke) {
    }
    assertFalse(ledgerId.get() == -1);
    assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
}

77. TestAuth#testCrashDuringAuth()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that when the plugin on the bookie crashes, the client doesn't
     * hang also, but it cannot write in any case.
     */
@Test(timeout = 30000)
public void testCrashDuringAuth() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(CrashAfter3BookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    try {
        connectAndWriteToBookie(clientConf, ledgerId);
        fail("Shouldn't get this far");
    } catch (BKException.BKNotEnoughBookiesException bke) {
    }
    assertFalse(ledgerId.get() == -1);
    assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
}

78. TestAuth#testCrashType2DuringAuth()

Project: bookkeeper
Source File: TestAuth.java
View license
/**
     * Test that when a bookie simply stops replying during auth, the client doesn't
     * hang also, but it cannot write in any case.
     */
@Test(timeout = 30000)
public void testCrashType2DuringAuth() throws Exception {
    ServerConfiguration bookieConf = newServerConfiguration();
    bookieConf.setBookieAuthProviderFactoryClass(CrashType2After3BookieAuthProviderFactory.class.getName());
    ClientConfiguration clientConf = newClientConfiguration();
    clientConf.setClientAuthProviderFactoryClass(SendUntilCompleteClientAuthProviderFactory.class.getName());
    crashType2bookieInstance = startAndStoreBookie(bookieConf);
    AtomicLong ledgerId = new AtomicLong(-1);
    try {
        connectAndWriteToBookie(clientConf, ledgerId);
        fail("Shouldn't get this far");
    } catch (BKException.BKNotEnoughBookiesException bke) {
    }
    assertFalse(ledgerId.get() == -1);
    assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
}

79. MethodTracker#hit()

Project: btrace
Source File: MethodTracker.java
View license
/**
     * Records the invocation of a certain method and indicates whether
     * it should be traced or not (sampling).
     * This method will be called when using the average sampling mode.
     *
     * @param methodId The method id - generated by the {@linkplain MethodID} class
     * @return {@code true} if the invocation should be traced
     */
public static boolean hit(int methodId) {
    int mean = means[methodId];
    if (mean == 0) {
        return true;
    }
    AtomicLong l = counters[methodId];
    if (l.getAndDecrement() <= 0) {
        int inc = rndIntProvider.nextInt(mean) + 1;
        l.addAndGet(inc);
        return true;
    }
    return false;
}

80. MethodTracker#hitTimed()

Project: btrace
Source File: MethodTracker.java
View license
/**
     * Records the invocation of a certain method alongside the timestamp
     * and indicates whether it should be traced or not (sampling).
     * This method will be called when using the average sampling mode.
     *
     * @param methodId The method id - generated by the {@linkplain MethodID} class
     * @return a positive number (invocation time stamp) if the invocation should be traced
     */
public static long hitTimed(int methodId) {
    int mean = means[methodId];
    if (mean == 0) {
        long ts = System.nanoTime();
        tsArray[methodId].set(ts);
        return ts;
    }
    AtomicLong l = counters[methodId];
    if (l.getAndDecrement() <= 0) {
        long ts = System.nanoTime();
        int inc = rndIntProvider.nextInt(mean) + 1;
        l.addAndGet(inc);
        tsArray[methodId].set(ts);
        return ts;
    }
    return 0L;
}

81. SuperConsoleEventBusListener#buildRuleSuspended()

View license
@Override
@Subscribe
public void buildRuleSuspended(BuildRuleEvent.Suspended suspended) {
    super.buildRuleSuspended(suspended);
    Optional<? extends BuildRuleEvent> started = Preconditions.checkNotNull(threadsToRunningBuildRuleEvent.put(suspended.getThreadId(), Optional.<BuildRuleEvent>absent()));
    Preconditions.checkState(started.isPresent());
    Preconditions.checkState(suspended.getBuildRule().equals(started.get().getBuildRule()));
    AtomicLong current = accumulatedRuleTime.get(suspended.getBuildRule().getBuildTarget());
    // while we're processing this one, so we have to check that the current counter exists.
    if (current != null) {
        current.getAndAdd(suspended.getTimestamp() - started.get().getTimestamp());
    }
}

82. AtomicLongMap#remove()

Project: cachecloud
Source File: AtomicLongMap.java
View license
/**
     * Removes and returns the value associated with {@code key}. If {@code key} is not
     * in the map, this method has no effect and returns zero.
     */
public long remove(K key) {
    AtomicLong atomic = map.get(key);
    if (atomic == null) {
        return 0L;
    }
    for (; ; ) {
        long oldValue = atomic.get();
        if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
            // only remove after setting to zero, to avoid concurrent updates
            map.remove(key, atomic);
            // succeed even if the remove fails, since the value was already adjusted
            return oldValue;
        }
    }
}

83. AtomicLongMap#remove()

Project: cachecloud
Source File: AtomicLongMap.java
View license
/**
     * If {@code (key, value)} is currently in the map, this method removes it and returns
     * true; otherwise, this method returns false.
     */
boolean remove(K key, long value) {
    AtomicLong atomic = map.get(key);
    if (atomic == null) {
        return false;
    }
    long oldValue = atomic.get();
    if (oldValue != value) {
        return false;
    }
    if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
        // only remove after setting to zero, to avoid concurrent updates
        map.remove(key, atomic);
        // succeed even if the remove fails, since the value was already adjusted
        return true;
    }
    // value changed
    return false;
}

84. AtomicLongMap#remove()

Project: cachecloud
Source File: AtomicLongMap.java
View license
/**
     * Removes and returns the value associated with {@code key}. If {@code key} is not
     * in the map, this method has no effect and returns zero.
     */
public long remove(K key) {
    AtomicLong atomic = map.get(key);
    if (atomic == null) {
        return 0L;
    }
    for (; ; ) {
        long oldValue = atomic.get();
        if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
            // only remove after setting to zero, to avoid concurrent updates
            map.remove(key, atomic);
            // succeed even if the remove fails, since the value was already adjusted
            return oldValue;
        }
    }
}

85. AtomicLongMap#remove()

Project: cachecloud
Source File: AtomicLongMap.java
View license
/**
     * If {@code (key, value)} is currently in the map, this method removes it and returns
     * true; otherwise, this method returns false.
     */
boolean remove(K key, long value) {
    AtomicLong atomic = map.get(key);
    if (atomic == null) {
        return false;
    }
    long oldValue = atomic.get();
    if (oldValue != value) {
        return false;
    }
    if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
        // only remove after setting to zero, to avoid concurrent updates
        map.remove(key, atomic);
        // succeed even if the remove fails, since the value was already adjusted
        return true;
    }
    // value changed
    return false;
}

86. ConnectionLimitHandler#channelInactive()

View license
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    counter.decrementAndGet();
    InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();
    AtomicLong count = connectionsPerClient.get(address);
    if (count != null) {
        if (count.decrementAndGet() <= 0) {
            connectionsPerClient.remove(address);
        }
    }
    ctx.fireChannelInactive();
}

87. BasicStreamWriterSizeCollector#received()

View license
@Override
public synchronized void received(Id.Stream streamId, long dataSize) {
    AtomicLong value = streamSizes.get(streamId);
    if (value == null) {
        value = streamSizes.putIfAbsent(streamId, new AtomicLong(dataSize));
    }
    if (value != null) {
        value.addAndGet(dataSize);
    }
    LOG.trace("Received data for stream {}: {}B. Total size is now {}", streamId, dataSize, value == null ? dataSize : value.get());
}

88. TestUtils#runMultipleTimesAndVerifyAvgRuntime()

Project: Chronicle-Engine
Source File: TestUtils.java
View license
public static void runMultipleTimesAndVerifyAvgRuntime(IntConsumer setup, Runnable testToRun, int noOfRuns, long maxRuntimeInNanos) {
    AtomicLong totalTime = new AtomicLong();
    // one warmup.
    IntStream.range(0, noOfRuns).forEach( e -> {
        setup.accept(e);
        long start = System.nanoTime();
        testToRun.run();
        long delta = System.nanoTime() - start;
        totalTime.addAndGet(delta);
    });
    long runtimeInNanos = printRuntime(totalTime.get(), noOfRuns);
    Assert.assertTrue(runtimeInNanos + " > " + maxRuntimeInNanos, runtimeInNanos <= maxRuntimeInNanos);
}

89. BufferTest#testWaitUntilTransportable()

Project: concourse
Source File: BufferTest.java
View license
@Test
public void testWaitUntilTransportable() throws InterruptedException {
    final AtomicLong later = new AtomicLong(0);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            ((Buffer) store).waitUntilTransportable();
            later.set(Time.now());
        }
    });
    thread.start();
    long before = Time.now();
    while (!((Buffer) store).canTransport()) {
        before = Time.now();
        add(TestData.getString(), TestData.getTObject(), TestData.getLong());
    }
    // make sure thread finishes before comparing
    thread.join();
    Assert.assertTrue(later.get() > before);
}

90. EvictionTest#updateRecency_onGetQuietly()

View license
@Test(dataProvider = "warmedMap")
public void updateRecency_onGetQuietly(final ConcurrentLinkedHashMap<Integer, Integer> map) {
    AtomicLong drainCounter = map.readBufferDrainAtWriteCount[readBufferIndex()];
    Node<Integer, Integer> first = map.evictionDeque.peek();
    Node<Integer, Integer> last = map.evictionDeque.peekLast();
    long drained = drainCounter.get();
    map.getQuietly(first.key);
    map.drainBuffers();
    assertThat(map.evictionDeque.peekFirst(), is(first));
    assertThat(map.evictionDeque.peekLast(), is(last));
    assertThat(drainCounter.get(), is(drained));
}

91. EvictionTest#drain_onRead()

View license
@Test(dataProvider = "warmedMap")
public void drain_onRead(ConcurrentLinkedHashMap<Integer, Integer> map) {
    AtomicReference<Node<Integer, Integer>>[] buffer = map.readBuffers[readBufferIndex()];
    AtomicLong writeCounter = map.readBufferWriteCount[readBufferIndex()];
    for (int i = 0; i < READ_BUFFER_THRESHOLD; i++) {
        map.get(1);
    }
    int pending = 0;
    for (AtomicReference<?> slot : buffer) {
        if (slot.get() != null) {
            pending++;
        }
    }
    assertThat(pending, is(equalTo(READ_BUFFER_THRESHOLD)));
    assertThat((int) writeCounter.get(), is(equalTo(pending)));
    map.get(1);
    assertThat(map.readBufferReadCount[readBufferIndex()], is(equalTo(writeCounter.get())));
    for (int i = 0; i < map.readBuffers.length; i++) {
        assertThat(map.readBuffers[readBufferIndex()][i].get(), is(nullValue()));
    }
}

92. ServerStateMachineTest#createStateMachine()

Project: copycat
Source File: ServerStateMachineTest.java
View license
@BeforeMethod
public void createStateMachine() throws Throwable {
    Serializer serializer = new Serializer().resolve(new ClientRequestTypeResolver(), new ClientResponseTypeResolver(), new ProtocolSerialization(), new ServerSerialization(), new StorageSerialization()).disableWhitelist();
    callerContext = new SingleThreadContext("caller", serializer.clone());
    stateContext = new SingleThreadContext("state", serializer.clone());
    LocalServerRegistry registry = new LocalServerRegistry();
    transport = new LocalTransport(registry);
    Storage storage = new Storage(StorageLevel.MEMORY);
    ServerMember member = new ServerMember(Member.Type.ACTIVE, new Address("localhost", 5000), new Address("localhost", 6000), Instant.now());
    new SingleThreadContext("test", serializer.clone()).executor().execute(() -> {
        state = new ServerContext("test", member.type(), member.serverAddress(), member.clientAddress(), storage, serializer, TestStateMachine::new, new ConnectionManager(new LocalTransport(registry).client()), callerContext);
        resume();
    });
    await(1000);
    timestamp = System.currentTimeMillis();
    sequence = new AtomicLong();
}

93. ClusterTest#testBlockOnEvent()

Project: copycat
Source File: ClusterTest.java
View license
/**
   * Tests blocking within an event thread.
   */
public void testBlockOnEvent() throws Throwable {
    createServers(3);
    AtomicLong index = new AtomicLong();
    CopycatClient client = createClient();
    client.onEvent("test",  event -> {
        threadAssertEquals(index.get(), event);
        try {
            threadAssertTrue(index.get() <= client.submit(new TestQuery(Query.ConsistencyLevel.LINEARIZABLE)).get(10, TimeUnit.SECONDS));
        } catch (InterruptedExceptionTimeoutException | ExecutionException |  e) {
            threadFail(e);
        }
        resume();
    });
    client.submit(new TestEvent(true)).thenAccept( result -> {
        threadAssertNotNull(result);
        index.compareAndSet(0, result);
        resume();
    });
    await(10000, 2);
}

94. PubsubUnboundedSourceTest#setupOneMessage()

View license
private void setupOneMessage(Iterable<IncomingMessage> incoming) {
    now = new AtomicLong(REQ_TIME);
    clock = new Clock() {

        @Override
        public long currentTimeMillis() {
            return now.get();
        }
    };
    factory = PubsubTestClient.createFactoryForPull(clock, SUBSCRIPTION, ACK_TIMEOUT_S, incoming);
    PubsubUnboundedSource<String> source = new PubsubUnboundedSource<>(clock, factory, null, null, SUBSCRIPTION, StringUtf8Coder.of(), TIMESTAMP_LABEL, ID_LABEL);
    primSource = new PubsubSource<>(source);
}

95. DefaultDempsyExecutor#start()

Project: Dempsy
Source File: DefaultDempsyExecutor.java
View license
@Override
public void start() {
    if (threadPoolSize == -1) {
        // figure out the number of cores.
        int cores = Runtime.getRuntime().availableProcessors();
        // why? I don't know. If you don't like it 
        int cpuBasedThreadCount = (int) Math.ceil((double) cores * m) + additionalThreads;
        //   then use the other constructor
        threadPoolSize = Math.max(cpuBasedThreadCount, minNumThreads);
    }
    executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadPoolSize);
    schedule = Executors.newSingleThreadScheduledExecutor();
    numLimited = new AtomicLong(0);
    if (maxNumWaitingLimitedTasks < 0)
        maxNumWaitingLimitedTasks = 20 * threadPoolSize;
}

96. CountingMapTest#testSnapshot()

Project: druid
Source File: CountingMapTest.java
View license
@Test
public void testSnapshot() {
    long defaultValue = 10;
    String defaultKey = "defaultKey";
    mapObject.add(defaultKey, defaultValue);
    ImmutableMap snapShotMap = (ImmutableMap) mapObject.snapshot();
    Assert.assertEquals("Maps size does not match", mapObject.size(), snapShotMap.size());
    long expected = (long) snapShotMap.get(defaultKey);
    AtomicLong actual = (AtomicLong) mapObject.get(defaultKey);
    Assert.assertEquals("Values for key = " + defaultKey + " does not match", actual.longValue(), expected);
}

97. KafkaLookupExtractorFactoryTest#testCacheKeyScramblesDifferentStarts()

View license
@Test
public void testCacheKeyScramblesDifferentStarts() {
    final int n = 1000;
    final KafkaLookupExtractorFactory factory = new KafkaLookupExtractorFactory(cacheManager, TOPIC, DEFAULT_PROPERTIES);
    factory.getMapRef().set(ImmutableMap.<String, String>of());
    final AtomicLong events = factory.getDoubleEventCount();
    final List<byte[]> byteArrays = new ArrayList<>(n);
    for (int i = 0; i < n; ++i) {
        final LookupExtractor extractor = factory.get();
        final byte[] myKey = extractor.getCacheKey();
        // Not terribly efficient.. but who cares
        for (byte[] byteArray : byteArrays) {
            Assert.assertFalse(Arrays.equals(byteArray, myKey));
        }
        byteArrays.add(myKey);
        events.incrementAndGet();
    }
    Assert.assertEquals(n, byteArrays.size());
}

98. ForkJoinPool#getStealCount()

Project: ehcache3
Source File: ForkJoinPool.java
View license
/**
     * Returns an estimate of the total number of tasks stolen from
     * one thread's work queue by another. The reported value
     * underestimates the actual total number of steals when the pool
     * is not quiescent. This value may be useful for monitoring and
     * tuning fork/join programs: in general, steal counts should be
     * high enough to keep threads busy, but low enough to avoid
     * overhead and contention across threads.
     *
     * @return the number of steals
     */
public long getStealCount() {
    AtomicLong sc = stealCounter;
    long count = (sc == null) ? 0L : sc.get();
    WorkQueue[] ws;
    WorkQueue w;
    if ((ws = workQueues) != null) {
        for (int i = 1; i < ws.length; i += 2) {
            if ((w = ws[i]) != null)
                count += w.nsteals;
        }
    }
    return count;
}

99. CacheTests#testWeigher()

Project: elasticsearch
Source File: CacheTests.java
View license
// cache some entries and exceed the maximum weight, then check that the cache has the expected weight and the
// expected evictions occurred
public void testWeigher() {
    int maximumWeight = 2 * numberOfEntries;
    int weight = randomIntBetween(2, 10);
    AtomicLong evictions = new AtomicLong();
    Cache<Integer, String> cache = CacheBuilder.<Integer, String>builder().setMaximumWeight(maximumWeight).weigher(( k,  v) -> weight).removalListener( notification -> evictions.incrementAndGet()).build();
    for (int i = 0; i < numberOfEntries; i++) {
        cache.put(i, Integer.toString(i));
    }
    // cache weight should be the largest multiple of weight less than maximumWeight
    assertEquals(weight * (maximumWeight / weight), cache.weight());
    // the number of evicted entries should be the number of entries that fit in the excess weight
    assertEquals((int) Math.ceil((weight - 2) * numberOfEntries / (1.0 * weight)), evictions.get());
    assertEquals(evictions.get(), cache.stats().getEvictions());
}

100. InMemoryTransaction#createObject()

Project: elide
Source File: InMemoryTransaction.java
View license
@Override
public <T> T createObject(Class<T> entityClass) {
    if (dataStore.get(entityClass) == null) {
        dataStore.putIfAbsent(entityClass, new ConcurrentHashMap<>());
        TYPEIDS.putIfAbsent(entityClass, new AtomicLong(1));
    }
    AtomicLong idValue = TYPEIDS.get(entityClass);
    String id = String.valueOf(idValue.getAndIncrement());
    try {
        T instance = entityClass.newInstance();
        setId(instance, id);
        return instance;
    } catch (InstantiationExceptionIllegalAccessException |  e) {
        e.printStackTrace();
    }
    return null;
}