Java Code Examples for java.util.concurrent.atomic.AtomicLong

The following are top voted examples for showing how to use java.util.concurrent.atomic.AtomicLong. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: MaxSim   File: Test7009231.java   Source Code and License 7 votes vote down vote up
private static void doTest(int nThreads) throws InterruptedException {
    Thread[]         aThreads = new Thread[nThreads];
    final AtomicLong atl      = new AtomicLong();

    for (int i = 0; i < nThreads; i++) {
      aThreads[i] = new RunnerThread(atl, 1L << (8 * i));
    }

    for (int i = 0; i < nThreads; i++) {
      aThreads[i].start();
    }

    for (int i = 0; i < nThreads; i++) {
      aThreads[i].join();
    }
}
 
Example 2
Project: RxJava3-preview   File: BackpressureHelper.java   Source Code and License 7 votes vote down vote up
/**
 * Atomically adds the positive value n to the requested value in the AtomicLong and
 * caps the result at Long.MAX_VALUE and returns the previous value and
 * considers Long.MIN_VALUE as a cancel indication (no addition then).
 * @param requested the AtomicLong holding the current requested value
 * @param n the value to add, must be positive (not verified)
 * @return the original value before the add
 */
public static long addCancel(AtomicLong requested, long n) {
    for (;;) {
        long r = requested.get();
        if (r == Long.MIN_VALUE) {
            return Long.MIN_VALUE;
        }
        if (r == Long.MAX_VALUE) {
            return Long.MAX_VALUE;
        }
        long u = addCap(r, n);
        if (requested.compareAndSet(r, u)) {
            return r;
        }
    }
}
 
Example 3
Project: scala-playground   File: Main.java   Source Code and License 6 votes vote down vote up
public static <T extends ImmutableTrade> void runSimpleQuery(List<T> immutableTrades) {
  Comparator<ImmutableTrade> comparator = Comparator.comparing(ImmutableTrade::getExchangeRate);
  Predicate<ImmutableTrade> predicate = t -> t.getCurrency1().equalsIgnoreCase("GBP") &&
      t.getCurrency2().equalsIgnoreCase("USD") &&
      t.getBuySell().equalsIgnoreCase("Buy");

  final AtomicLong ignore = new AtomicLong(0);

  int n = 10;

  System.out.println("Running a filter and sort on the trades (" + n + " times)");
  long start = System.nanoTime();
  for (int i = 0; i < n; i++) {
    System.gc();

    immutableTrades.stream()
        .filter(predicate)
        .sorted(comparator)
        .limit(10)
        .forEach(p -> ignore.set(p.getId()));
  }

  System.out.println("ignore: " + ignore.get());
  System.out.printf("Query time = %.3f seconds%n%n", (System.nanoTime() - start) / 1e9);
}
 
Example 4
Project: aliyun-tablestore-hbase-client   File: OTSAdapter.java   Source Code and License 6 votes vote down vote up
private void doCommits(String tableName, final List<com.alicloud.tablestore.adaptor.struct.OPut> puts) throws IOException {
  boolean flushSuccessfully = false;
  try {
    otsProxy.putMultiple(tableName, puts);
    flushSuccessfully = true;
  } finally {
    if (!flushSuccessfully && !getClearBufferOnFail(tableName)) {
      ArrayList<com.alicloud.tablestore.adaptor.struct.OPut> tableWriteBuffer = getTableWriteBuffer(tableName);
      synchronized (tableWriteBuffer) {
        AtomicLong currentBufferSize = getTableCurrentBufferSize(tableName);
        for (com.alicloud.tablestore.adaptor.struct.OPut put : puts) {
          tableWriteBuffer.add(put);
          currentBufferSize.addAndGet(put.getWritableSize());
        }
      }
    }
  }
}
 
Example 5
Project: GitHub   File: CacheUtils.java   Source Code and License 6 votes vote down vote up
private CacheManager(final File cacheDir, final long sizeLimit, final int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    mThread = new Thread(new Runnable() {
        @Override
        public void run() {
            int size = 0;
            int count = 0;
            final File[] cachedFiles = cacheDir.listFiles();
            if (cachedFiles != null) {
                for (File cachedFile : cachedFiles) {
                    size += cachedFile.length();
                    count += 1;
                    lastUsageDates.put(cachedFile, cachedFile.lastModified());
                }
                cacheSize.getAndAdd(size);
                cacheCount.getAndAdd(count);
            }
        }
    });
    mThread.start();
}
 
Example 6
Project: uavstack   File: LongCodec.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    final JSONLexer lexer = parser.getLexer();

    Long longObject;
    if (lexer.token() == JSONToken.LITERAL_INT) {
        long longValue = lexer.longValue();
        lexer.nextToken(JSONToken.COMMA);
        longObject = Long.valueOf(longValue);
    } else {

        Object value = parser.parse();

        if (value == null) {
            return null;
        }

        longObject = TypeUtils.castToLong(value);
    }
    
    if (clazz == AtomicLong.class) {
        return (T) new AtomicLong(longObject.longValue());
    }
    
    return (T) longObject;
}
 
Example 7
Project: ditb   File: TestSplitLogWorker.java   Source Code and License 6 votes vote down vote up
private boolean waitForCounterBoolean(final AtomicLong ctr, final long oldval, final long newval,
    long timems, boolean failIfTimeout) throws Exception {

  long timeWaited = TEST_UTIL.waitFor(timems, 10, failIfTimeout,
    new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
          return (ctr.get() >= newval);
    }
  });

  if( timeWaited > 0) {
    // when not timed out
    assertEquals(newval, ctr.get());
  }
  return true;
}
 
Example 8
Project: boohee_v5.6   File: OperatorGroupBy.java   Source Code and License 6 votes vote down vote up
private void emitItem(GroupState<K, T> groupState, Object item) {
    Queue<Object> q = groupState.buffer;
    AtomicLong keyRequested = groupState.requested;
    REQUESTED.decrementAndGet(this);
    if (keyRequested == null || keyRequested.get() <= 0 || !(q == null || q.isEmpty())) {
        q.add(item);
        BUFFERED_COUNT.incrementAndGet(this);
        if (groupState.count.getAndIncrement() == 0) {
            pollQueue(groupState);
        }
    } else {
        nl.accept(groupState.getObserver(), item);
        if (keyRequested.get() != Long.MAX_VALUE) {
            keyRequested.decrementAndGet();
        }
    }
    requestMoreIfNecessary();
}
 
Example 9
Project: ZooKeeper   File: ReferenceCountedACLCache.java   Source Code and License 6 votes vote down vote up
public synchronized void addUsage(Long acl) {
    if (acl == OPEN_UNSAFE_ACL_ID) {
        return;
    }

    if (!longKeyMap.containsKey(acl)) {
        LOG.info("Ignoring acl " + acl + " as it does not exist in the cache");
        return;
    }

    AtomicLong count = referenceCounter.get(acl);
    if (count == null) {
        referenceCounter.put(acl, new AtomicLongWithEquals(1));
    } else {
        count.incrementAndGet();
    }
}
 
Example 10
Project: GitHub   File: RealmTests.java   Source Code and License 6 votes vote down vote up
@Test
public void waitForChange_runWithRealmThread() throws InterruptedException {
    final CountDownLatch bgRealmStarted = new CountDownLatch(1);
    final CountDownLatch bgRealmFished = new CountDownLatch(1);
    final AtomicBoolean bgRealmChangeResult = new AtomicBoolean(false);
    final AtomicLong bgRealmResultSize = new AtomicLong(0);

    RealmThread thread = new RealmThread(realmConfig, new RealmThread.RealmRunnable() {
        @Override
        public void run(Realm realm) {
            bgRealmStarted.countDown();
            bgRealmChangeResult.set(realm.waitForChange());
            bgRealmResultSize.set(realm.where(AllTypes.class).count());
            realm.close();
            bgRealmFished.countDown();
        }
    });
    thread.start();

    TestHelper.awaitOrFail(bgRealmStarted);
    populateTestRealm();
    TestHelper.awaitOrFail(bgRealmFished);
    assertTrue(bgRealmChangeResult.get());
    assertEquals(TEST_DATA_SIZE, bgRealmResultSize.get());
}
 
Example 11
Project: boohee_v5.6   File: LongCodec.java   Source Code and License 6 votes vote down vote up
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    Long longObject;
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 2) {
        long longValue = lexer.longValue();
        lexer.nextToken(16);
        longObject = Long.valueOf(longValue);
    } else {
        Object value = parser.parse();
        if (value == null) {
            return null;
        }
        longObject = TypeUtils.castToLong(value);
    }
    if (clazz == AtomicLong.class) {
        return new AtomicLong(longObject.longValue());
    }
    return longObject;
}
 
Example 12
Project: morf   File: TestDataSetUtilsVolume.java   Source Code and License 6 votes vote down vote up
/**
 * Creates and destroys lots of records in such a way that some may end up getting past
 * the eden space.
 */
@Test
@Ignore
public void testSimulateHighVolumeWithBoxedData() throws InterruptedException {
  BlockingQueue<Iterable<Record>> queue = new ArrayBlockingQueue<>(QUEUE_DEPTH);
  ExecutorService pool = Executors.newFixedThreadPool(POOL_SIZE);
  try {
    timerStart = new AtomicLong(System.currentTimeMillis());
    processed = new AtomicLong(0);
    IntStream.range(0, 10).forEach(i -> pool.execute(() -> produce(queue, this::randomiseObjects)));
    IntStream.range(0, 8).forEach(i -> pool.execute(() -> consume(queue, this::readObjects)));
  } finally {
    pool.shutdown();
    pool.awaitTermination(3, TimeUnit.MINUTES);
  }
}
 
Example 13
Project: okdownload   File: MultiPointOutputStream.java   Source Code and License 6 votes vote down vote up
public void ensureSyncComplete(int blockIndex) {
    final AtomicLong noSyncLength = noSyncLengthMap.get(blockIndex);
    if (noSyncLength != null && noSyncLength.get() > 0) {
        // sync to store
        if (syncRunning) {
            // wait for sync
            parkThreadList.add(Thread.currentThread());
            while (true) {
                LockSupport.parkNanos(WAIT_SYNC_NANO);
                if (!syncRunning) break;
            }
        }

        // sync once, make sure data has been synced.
        syncRunning = true;
        syncRunnable.run();

    }
}
 
Example 14
Project: okdownload   File: MultiPointOutputStreamTest.java   Source Code and License 6 votes vote down vote up
@Test
public void write() throws IOException {
    final DownloadOutputStream outputStream = mock(DownloadOutputStream.class);
    doReturn(outputStream).when(multiPointOutputStream).outputStream(anyInt());
    multiPointOutputStream.syncRunning = true;

    final byte[] bytes = new byte[6];
    multiPointOutputStream.noSyncLengthMap.put(1, new AtomicLong());
    multiPointOutputStream.write(1, bytes, 6);

    verify(multiPointOutputStream).write(1, bytes, 6);

    multiPointOutputStream.noSyncLengthMap.put(2, new AtomicLong());
    multiPointOutputStream.write(2, bytes, 16);
    verify(multiPointOutputStream).write(2, bytes, 16);

    assertThat(multiPointOutputStream.allNoSyncLength.get()).isEqualTo(22);
    assertThat(multiPointOutputStream.noSyncLengthMap.get(1).get()).isEqualTo(6);
    assertThat(multiPointOutputStream.noSyncLengthMap.get(2).get()).isEqualTo(16);
}
 
Example 15
Project: sstore-soft   File: CETxnInputGenerator.java   Source Code and License 6 votes vote down vote up
public void initialize(){
    activeCompanyCount = companies.getCompanyCount();
    activeSecurityCount = SecurityHandler.getSecurityNum(myCustomerCount);
    industryCount = industries.getMaxKey();
    sectorCount = sectors.getMaxKey();
    startFromCompany = companies.generateCompId();

    maxActivePrePopulatedTradeID = (int)(( hoursOfInitialTrades * EGenDate.SecondsPerHour * ( activeCustomerCount / scaleFactor )) * TPCEConstants.AbortTrade / 100 );
    currentTradeID = new AtomicLong(maxActivePrePopulatedTradeID + 1);
    startTime = EGenDate.getDateFromTime(
    		TPCEConstants.initialTradePopulationBaseYear,
    		TPCEConstants.initialTradePopulationBaseMonth,
    		TPCEConstants.initialTradePopulationBaseDay,
    		TPCEConstants.initialTradePopulationBaseHour,
    		TPCEConstants.initialTradePopulationBaseMinute,
    		TPCEConstants.initialTradePopulationBaseSecond,
    		TPCEConstants.initialTradePopulationBaseFraction );
}
 
Example 16
Project: gather   File: TestGatherUtils.java   Source Code and License 6 votes vote down vote up
@Test
public void testCompareNumbers() {
	Assert.assertTrue(GatherUtils.compareNumbers((byte) 32, 64d) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers((short) 32, 64d) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers((int) 32, 64d) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers((long) 32, 64d) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers((float) 32, 64d) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers((double) 32, new AtomicLong(64)) < 0);

	Assert.assertTrue(GatherUtils.compareNumbers(new AtomicInteger(32), new AtomicLong(64)) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new AtomicLong(32), (short) 64) < 0);

	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), new BigDecimal(64)) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (byte) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (short) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (int) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (long) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (float) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), (double) 64) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), new AtomicInteger(64)) < 0);
	Assert.assertTrue(GatherUtils.compareNumbers(new BigDecimal(32), new AtomicLong(64)) < 0);

}
 
Example 17
Project: tusRx   File: PatchHandlerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testWrongOffsetResponds409() {
 // arrange
    when(request.getUuid()).thenReturn(uuid);
    when(request.getHeader("Upload-Offset")).thenReturn(Optional.of("10"));
    when(upload.getOffset()).thenReturn(new AtomicLong(50L));
    when(upload.uploadChunk(request))
            .thenReturn(Observable.just(1L, 2L, 3L).concatWith(Observable.error(new IOException())));

    // act
    Observable<TusResponse> response = handler.handle();

    // assert
    response.toBlocking().subscribe(tr -> {
        assertThat(tr.getStatusCode()).isEqualTo(409);
    }, x -> logger.info("", x));
}
 
Example 18
Project: JRediClients   File: RedissonTestRunListener.java   Source Code and License 6 votes vote down vote up
@Override
public void testRunStarted(Description description) throws Exception {
    super.testRunStarted(description);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        running.set(Boolean.FALSE);
    }));
    new Thread(() -> {
        final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        final AtomicLong u = new AtomicLong(runtimeBean.getUptime());
        while (running.get()) {
            try {
                long upTime = runtimeBean.getUptime();
                if (upTime >= u.get() + 10000) {
                    u.set(upTime);
                    System.out.printf("Test Up Time    = %.3f (s)%n", upTime / 1000d);
                    System.out.printf("Heap Usage      = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.printf("None Heap Usage = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.println("=============================");
                }
                Thread.currentThread().sleep(10000l);
            } catch (InterruptedException ex) {
                Logger.getLogger(RedissonTestRunListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }).start();
}
 
Example 19
Project: JavaTools   File: ThreadFactoryBuilder.java   Source Code and License 6 votes vote down vote up
public ThreadFactory build(ThreadFactoryBuilder builder) {
    final String nameFormat = builder.nameFormat;
    final Boolean daemon = builder.daemon;
    final Integer priority = builder.priority;
    final AtomicLong count = nameFormat != null ? new AtomicLong(0L) : null;

    return (runnable)->{
        Thread thread = Executors.defaultThreadFactory().newThread(runnable);
        if (nameFormat != null) {
            thread.setName(ThreadFactoryBuilder.format(nameFormat, count.getAndIncrement()));
        }

        if (daemon != null) {
            thread.setDaemon(daemon.booleanValue());
        }

        if (priority != null) {
            thread.setPriority(priority.intValue());
        }

        return thread;
    };
}
 
Example 20
Project: monarch   File: WriteAheadLog.java   Source Code and License 6 votes vote down vote up
/**
 * Delete all file for a table
 * 
 * @param tableName
 */
public void deleteTable(String tableName) {
  if (!initialized) {
    return;
  }
  String[] filesTodelete = getAllFilesForTable(tableName);
  for (String file : filesTodelete) {
    deleteWALFile(file);
  }
  closeAllWALFilesForTable(tableName);
  /** remove the sequence-no for the table that is getting deleted **/
  Matcher matcher = Pattern.compile("^" + tableName + "_[0-9]+$").matcher("_dummy_");
  Iterator<Map.Entry<String, AtomicLong>> iterator = bucketSeqNoMap.entrySet().iterator();
  Map.Entry<String, AtomicLong> entry;
  while (iterator.hasNext()) {
    entry = iterator.next();
    if (matcher.reset(entry.getKey()).matches()) {
      iterator.remove();
    }
  }
}
 
Example 21
Project: Elasticsearch   File: ChildMemoryCircuitBreaker.java   Source Code and License 6 votes vote down vote up
/**
 * Create a circuit breaker that will break if the number of estimated
 * bytes grows above the limit. All estimations will be multiplied by
 * the given overheadConstant. Uses the given oldBreaker to initialize
 * the starting offset.
 * @param settings settings to configure this breaker
 * @param parent parent circuit breaker service to delegate tripped breakers to
 * @param name the name of the breaker
 * @param oldBreaker the previous circuit breaker to inherit the used value from (starting offset)
 */
public ChildMemoryCircuitBreaker(BreakerSettings settings, ChildMemoryCircuitBreaker oldBreaker,
                                 ESLogger logger, HierarchyCircuitBreakerService parent, String name) {
    this.name = name;
    this.settings = settings;
    this.memoryBytesLimit = settings.getLimit();
    this.overheadConstant = settings.getOverhead();
    if (oldBreaker == null) {
        this.used = new AtomicLong(0);
        this.trippedCount = new AtomicLong(0);
    } else {
        this.used = oldBreaker.used;
        this.trippedCount = oldBreaker.trippedCount;
    }
    this.logger = logger;
    if (logger.isTraceEnabled()) {
        logger.trace("creating ChildCircuitBreaker with settings {}", this.settings);
    }
    this.parent = parent;
}
 
Example 22
Project: Jaffree   File: FFmpegTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testProgress() throws Exception {
    Path tempDir = Files.createTempDirectory("jaffree");
    Path outputPath = tempDir.resolve("test.mkv");

    final AtomicLong counter = new AtomicLong();

    ProgressListener listener = new ProgressListener() {
        @Override
        public void onProgress(FFmpegProgress progress) {
            counter.incrementAndGet();
        }
    };

    FFmpegResult result = FFmpeg.atPath(BIN)
            .addInput(UrlInput.fromPath(SMALL_FLV))
            .addOutput(UrlOutput.toPath(outputPath))
            .setProgressListener(listener)
            .execute();

    Assert.assertNotNull(result);
    Assert.assertTrue(counter.get() > 0);
}
 
Example 23
Project: wamp2spring   File: IdGeneratorTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testNewLinearId() {
	AtomicLong id = new AtomicLong(0);
	assertThat(IdGenerator.newLinearId(id)).isEqualTo(1);
	assertThat(IdGenerator.newLinearId(id)).isEqualTo(2);

	id.set(IdGenerator.MAX - 1L);
	assertThat(IdGenerator.newLinearId(id)).isEqualTo(IdGenerator.MAX);
	assertThat(IdGenerator.newLinearId(id)).isEqualTo(1L);
}
 
Example 24
Project: rmq4note   File: StoreStatsService.java   Source Code and License 5 votes vote down vote up
private String putMessageDistributeTimeToString() {
    final AtomicLong[] times = this.putMessageDistributeTime;
    if (null == times)
        return null;

    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < times.length; i++) {
        long value = times[i].get();
        sb.append(String.format("%s:%d", PUT_MESSAGE_ENTIRE_TIME_MAX_DESC[i], value));
        sb.append(" ");
    }

    return sb.toString();
}
 
Example 25
Project: dubbo2   File: LoadBalanceTest.java   Source Code and License 5 votes vote down vote up
@Test
    public void testRandomLoadBalance_select() {
        int runs = 1000;
        Map<Invoker,AtomicLong> counter = getInvokeCounter(runs,RandomLoadBalance.NAME);
        for (Invoker minvoker :counter.keySet() ){
            Long count = counter.get(minvoker).get();
//            System.out.println(count);
            Assert.assertTrue("abs diff shoud < avg", Math.abs(count-runs/(0f+invokers.size())) <runs/(0f+invokers.size()));
        }
    }
 
Example 26
Project: openjdk-jdk10   File: AtomicLong9Test.java   Source Code and License 5 votes vote down vote up
/**
 * getOpaque returns the last value set
 */
public void testGetOpaqueSet() {
    AtomicLong ai = new AtomicLong(1);
    assertEquals(1, ai.getOpaque());
    ai.set(2);
    assertEquals(2, ai.getOpaque());
    ai.set(-3);
    assertEquals(-3, ai.getOpaque());
}
 
Example 27
Project: sstable-adaptor   File: RestorableMeter.java   Source Code and License 5 votes vote down vote up
/**
 * Restores a RestorableMeter from the last seen 15m and 2h rates.
 * @param lastM15Rate the last-seen 15m rate, in terms of events per second
 * @param lastM120Rate the last seen 2h rate, in terms of events per second
 */
public RestorableMeter(double lastM15Rate, double lastM120Rate)
{
    this.m15Rate = new RestorableEWMA(lastM15Rate, TimeUnit.MINUTES.toSeconds(15));
    this.m120Rate = new RestorableEWMA(lastM120Rate, TimeUnit.MINUTES.toSeconds(120));
    this.startTime = this.clock.getTick();
    this.lastTick = new AtomicLong(startTime);
}
 
Example 28
Project: https-github.com-apache-zookeeper   File: CreateTTLTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testMulti()
        throws IOException, KeeperException, InterruptedException {
    Op createTtl = Op.create("/a", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, 100);
    Op createTtlSequential = Op.create("/b", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, 200);
    Op createNonTtl = Op.create("/c", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    List<OpResult> results = zk.multi(Arrays.asList(createTtl, createTtlSequential, createNonTtl));
    String sequentialPath = ((OpResult.CreateResult)results.get(1)).getPath();

    final AtomicLong fakeElapsed = new AtomicLong(0);
    ContainerManager containerManager = newContainerManager(fakeElapsed);
    containerManager.checkContainers();
    Assert.assertNotNull("node should not have been deleted yet", zk.exists("/a", false));
    Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
    Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));

    fakeElapsed.set(110);
    containerManager.checkContainers();
    Assert.assertNull("node should have been deleted", zk.exists("/a", false));
    Assert.assertNotNull("node should not have been deleted yet", zk.exists(sequentialPath, false));
    Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));

    fakeElapsed.set(210);
    containerManager.checkContainers();
    Assert.assertNull("node should have been deleted", zk.exists("/a", false));
    Assert.assertNull("node should have been deleted", zk.exists(sequentialPath, false));
    Assert.assertNotNull("node should never be deleted", zk.exists("/c", false));
}
 
Example 29
Project: aliyun-log-flink-connector   File: LogDataFetcher.java   Source Code and License 5 votes vote down vote up
private static ExecutorService createShardConsumersThreadPool(final String subtaskName) {
    return Executors.newCachedThreadPool(new ThreadFactory() {
        public Thread newThread(Runnable runnable) {
            final AtomicLong threadCount = new AtomicLong(0);
            Thread thread = new Thread(runnable);
            thread.setName("shardConsumers-" + subtaskName + "-thread-" + threadCount.getAndIncrement());
            thread.setDaemon(true);
            return thread;
        }
    });
}
 
Example 30
Project: dble   File: TestInsertGlobalSeqPerf.java   Source Code and License 5 votes vote down vote up
@Override
public Runnable createJob(SimpleConPool conPool2, long myCount, int batch,
                          long startId, AtomicLong finshiedCount2,
                          AtomicLong failedCount2) {
    return new TravelRecordGlobalSeqInsertJob(conPool2,
            myCount, batch, startId, finshiedCount, failedCount);
}
 
Example 31
Project: agroal   File: DefaultMetricsRepository.java   Source Code and License 5 votes vote down vote up
private void setMaxValue(AtomicLong field, long value) {
    for ( long oldMax; value > ( oldMax = field.get() ); ) {
        if ( field.compareAndSet( oldMax, value ) ) {
            return;
        }
    }
}
 
Example 32
Project: test-as-you-think   File: ResultOfEventTest.java   Source Code and License 5 votes vote down vote up
@Test
public void should_verify_an_actual_atomic_long_is_conform_to_an_expected_result() {
    assertThat(resultOf(() -> {
        gwtMock.whenAnEventHappensInRelationToAnActionOfTheConsumer();
        return new AtomicLong(123);
    }).hasPositiveValue()).hasSameClassAs(assertThat(new AtomicLong()));
}
 
Example 33
Project: elasticsearch_my   File: TransportBulkActionTookTests.java   Source Code and License 5 votes vote down vote up
private void runTestTook(boolean controlled) throws Exception {
    String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/simple-bulk.json");
    // translate Windows line endings (\r\n) to standard ones (\n)
    if (Constants.WINDOWS) {
        bulkAction = Strings.replace(bulkAction, "\r\n", "\n");
    }
    BulkRequest bulkRequest = new BulkRequest();
    bulkRequest.add(bulkAction.getBytes(StandardCharsets.UTF_8), 0, bulkAction.length(), null, null, XContentType.JSON);
    AtomicLong expected = new AtomicLong();
    TransportBulkAction action = createAction(controlled, expected);
    action.doExecute(null, bulkRequest, new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(BulkResponse bulkItemResponses) {
            if (controlled) {
                assertThat(
                        bulkItemResponses.getTook().getMillis(),
                        equalTo(TimeUnit.MILLISECONDS.convert(expected.get(), TimeUnit.NANOSECONDS)));
            } else {
                assertThat(
                        bulkItemResponses.getTook().getMillis(),
                        greaterThanOrEqualTo(TimeUnit.MILLISECONDS.convert(expected.get(), TimeUnit.NANOSECONDS)));
            }
        }

        @Override
        public void onFailure(Exception e) {

        }
    });
}
 
Example 34
Project: MLE5109-Course-samples   File: Service.java   Source Code and License 5 votes vote down vote up
public Service(Collection<String> groups, int poolSize) {
    this.groups = groups;
    pendingRequests = new PendingRequests(groups, rwDMPersistenceSupraLock);
    threadPool = Executors.newFixedThreadPool(poolSize, new ThreadFactory() {
        private final AtomicLong counter = new AtomicLong();
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "TPWorker" + counter.incrementAndGet());
        }
    });

    messageProcessor = new AbstractProcessor<MessageDataModel>() {
        @Override
        protected void doProcess(MessageDataModel element) {
            pendingRequests.run(() -> processRequest(element), element.getGroup());
        }
    };
    recoveryMessageProcessor = new AbstractProcessor<RecoveryMessage>() {
        @Override
        protected void doProcess(RecoveryMessage element) {
            if (pendingRequests.requestExists(element.getGroup(), element.getId())) {
                Service.this.process(new MessageDataModel(element.data));
            }
        }
    };
    serviceStarted = new CountDownLatch(1);
    LOGGER.info("Created " + getClass().getSimpleName());
}
 
Example 35
Project: BetterRandom   File: Pcg64Random.java   Source Code and License 5 votes vote down vote up
@EntryPoint public Pcg64Random(final byte[] seed) {
  super(seed);
  if (seed.length != Long.BYTES) {
    throw new IllegalArgumentException("Pcg64Random requires an 8-byte seed");
  }
  internal = new AtomicLong(BinaryUtils.convertBytesToLong(seed));
}
 
Example 36
Project: xitk   File: ProcessLog.java   Source Code and License 5 votes vote down vote up
public void reset() {
    startTimeMs = System.currentTimeMillis();
    numProcessed = new AtomicLong(0);
    lastPrintTimeMs = new AtomicLong(0);
    measureDeque.clear();
    measureDeque.add(new MeasurePoint(startTimeMs, 0));
}
 
Example 37
Project: mycat-src-1.6.1-RELEASE   File: ByteBufferArena.java   Source Code and License 5 votes vote down vote up
public ByteBufferArena(int chunkSize, int pageSize, int chunkCount, int conReadBuferChunk) {
    try {
        this.chunkSize = chunkSize;
        this.pageSize = pageSize;
        this.chunkCount.set(chunkCount);
        this.conReadBuferChunk = conReadBuferChunk;

        q = new ByteBufferChunkList[6];
        q[5] = new ByteBufferChunkList(100, Integer.MAX_VALUE, chunkSize, pageSize, 0);
        q[4] = new ByteBufferChunkList(75, 100, chunkSize, pageSize, 0);
        q[3] = new ByteBufferChunkList(50, 100, chunkSize, pageSize, 0);
        q[2] = new ByteBufferChunkList(25, 75, chunkSize, pageSize, 0);
        q[1] = new ByteBufferChunkList(1, 50, chunkSize, pageSize, 0);
        q[0] = new ByteBufferChunkList(Integer.MIN_VALUE, 25, chunkSize, pageSize, chunkCount);

        q[0].nextList = q[1];
        q[1].nextList = q[2];
        q[2].nextList = q[3];
        q[3].nextList = q[4];
        q[4].nextList = q[5];
        q[5].nextList = null;

        q[5].prevList = q[4];
        q[4].prevList = q[3];
        q[3].prevList = q[2];
        q[2].prevList = q[1];
        q[1].prevList = q[0];
        q[0].prevList = null;

        capacity = new AtomicLong(6 * chunkCount * chunkSize);
        size = new AtomicLong(6 * chunkCount * chunkSize);
        sharedOptsCount = new ConcurrentHashMap<>();
        memoryUsage = new ConcurrentHashMap<>();
    } finally {
    }
}
 
Example 38
Project: Android-UtilCode   File: CacheUtils.java   Source Code and License 5 votes vote down vote up
private CacheManager(File cacheDir, long sizeLimit, int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    calculateCacheSizeAndCacheCount();
}
 
Example 39
Project: ditb   File: Canary.java   Source Code and License 5 votes vote down vote up
RegionServerTask(Connection connection, String serverName, HRegionInfo region,
    ExtendedSink sink, AtomicLong successes) {
  this.connection = connection;
  this.serverName = serverName;
  this.region = region;
  this.sink = sink;
  this.successes = successes;
}
 
Example 40
Project: ditb   File: RegionReplicaReplicationEndpoint.java   Source Code and License 5 votes vote down vote up
public RegionReplicaReplayCallable(ClusterConnection connection,
    RpcControllerFactory rpcControllerFactory, TableName tableName,
    HRegionLocation location, HRegionInfo regionInfo, byte[] row,List<Entry> entries,
    AtomicLong skippedEntries) {
  super(connection, rpcControllerFactory, location, tableName, row, regionInfo.getReplicaId());
  this.entries = entries;
  this.skippedEntries = skippedEntries;
  this.initialEncodedRegionName = regionInfo.getEncodedNameAsBytes();
}
 
Example 41
Project: GitHub   File: ACache.java   Source Code and License 5 votes vote down vote up
private ACacheManager(File cacheDir, long sizeLimit, int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    calculateCacheSizeAndCacheCount();
}
 
Example 42
Project: GitHub   File: RealmTests.java   Source Code and License 5 votes vote down vote up
@Test
public void waitForChange_withDataChange() throws InterruptedException {
    final CountDownLatch bgRealmOpened = new CountDownLatch(1);
    final CountDownLatch bgRealmClosed = new CountDownLatch(1);
    final AtomicBoolean bgRealmChangeResult = new AtomicBoolean(false);
    final AtomicLong bgRealmWaitForChangeResult = new AtomicLong(0);

    // Waits in background.
    final CountDownLatch signalTestFinished = new CountDownLatch(1);
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            Realm realm = Realm.getInstance(realmConfig);
            bgRealmOpened.countDown();
            bgRealmChangeResult.set(realm.waitForChange());
            bgRealmWaitForChangeResult.set(realm.where(AllTypes.class).count());
            realm.close();
            bgRealmClosed.countDown();
        }
    });
    thread.start();

    TestHelper.awaitOrFail(bgRealmOpened);
    populateTestRealm();
    TestHelper.awaitOrFail(bgRealmClosed);
    assertTrue(bgRealmChangeResult.get());
    assertEquals(TEST_DATA_SIZE, bgRealmWaitForChangeResult.get());
}
 
Example 43
Project: XFrame   File: XCacheManager.java   Source Code and License 5 votes vote down vote up
public XCacheManager(File cacheDir, long sizeLimit, int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    calculateCacheSizeAndCacheCount();
}
 
Example 44
Project: sentry   File: PlayerCountService.java   Source Code and License 5 votes vote down vote up
@Scheduled(cron = "10 * * * * ?")
void storePlayerCountMetrics() {
    ZonedDateTime timestamp = ZonedDateTime.now().truncatedTo(MINUTES);

    Map<String, AtomicLong> aggregations = new ConcurrentHashMap<>();

    metricRegistry.getGauges((name, metric) -> name.startsWith("UGC.GameServer.player_count"))
        .entrySet().stream()
        // all servers -> group into regions
        .collect(toMultimap(
            entry -> extractRegion(entry.getKey()),
            Map.Entry::getValue,
            MultimapBuilder.treeKeys().arrayListValues()::build))
        .entries()
        .forEach(entry -> aggregations.computeIfAbsent(entry.getKey(), k -> new AtomicLong())
            .addAndGet((Integer) entry.getValue().getValue()));

    aggregations.entrySet().stream()
        .filter(entry -> entry.getValue().get() > 0 || lastValueMap.getOrDefault(entry.getKey(), 0L) != 0)
        .forEach(entry -> {
            String region = entry.getKey();
            Long value = entry.getValue().get();
            if (lastValueMap.getOrDefault(entry.getKey(), 0L) == 0) {
                if (playerCountRepository.countByRegionAndValueAndTimestamp(region, value, timestamp) == 0) {
                    // add a 0 to the previous minute
                    playerCountRepository.save(new PlayerCount()
                        .timestamp(timestamp.minusMinutes(1))
                        .region(region)
                        .value(0L));
                }
            }
            playerCountRepository.save(new PlayerCount()
                .timestamp(timestamp)
                .region(region)
                .value(value));
            lastValueMap.put(region, value);
        });
}
 
Example 45
Project: cyberduck   File: CountingMetrics.java   Source Code and License 5 votes vote down vote up
@Override
public <T> void increment(final T key) {
    if(!metrics.containsKey(key)) {
        metrics.put(key, new AtomicLong());
    }
    metrics.get(key).getAndIncrement();
}
 
Example 46
Project: RxJava3-preview   File: QueueDrainHelper.java   Source Code and License 5 votes vote down vote up
/**
 * Signals the completion of the main sequence and switches to post-completion replay mode.
 *
 * <p>
 * Don't modify the queue after calling this method!
 *
 * <p>
 * Post-completion backpressure handles the case when a source produces values based on
 * requests when it is active but more values are available even after its completion.
 * In this case, the onComplete() can't just emit the contents of the queue but has to
 * coordinate with the requested amounts. This requires two distinct modes: active and
 * completed. In active mode, requests flow through and the queue is not accessed but
 * in completed mode, requests no-longer reach the upstream but help in draining the queue.
 * <p>
 * The algorithm utilizes the most significant bit (bit 63) of a long value (AtomicLong) since
 * request amount only goes up to Long.MAX_VALUE (bits 0-62) and negative values aren't
 * allowed.
 *
 * @param <T> the value type emitted
 * @param actual the target Subscriber to send events to
 * @param queue the queue to drain if in the post-complete state
 * @param state holds the request amount and the post-completed flag
 * @param isCancelled a supplier that returns true if the drain has been cancelled
 */
public static <T> void postComplete(Subscriber<? super T> actual,
                                    Queue<T> queue,
                                    AtomicLong state,
                                    BooleanSupplier isCancelled) {

    if (queue.isEmpty()) {
        actual.onComplete();
        return;
    }

    if (postCompleteDrain(state.get(), actual, queue, state, isCancelled)) {
        return;
    }

    for (; ; ) {
        long r = state.get();

        if ((r & COMPLETED_MASK) != 0L) {
            return;
        }

        long u = r | COMPLETED_MASK;
        // (active, r) -> (complete, r) transition
        if (state.compareAndSet(r, u)) {
            // if the requested amount was non-zero, drain the queue
            if (r != 0L) {
                postCompleteDrain(u, actual, queue, state, isCancelled);
            }

            return;
        }
    }

}
 
Example 47
Project: okdownload   File: BlockInfo.java   Source Code and License 5 votes vote down vote up
public BlockInfo(long startOffset, long contentLength, @IntRange(from = 0) long currentOffset) {
    if (startOffset < 0 || contentLength < 0 || currentOffset < 0) {
        throw new IllegalArgumentException();
    }

    this.startOffset = startOffset;
    this.contentLength = contentLength;
    this.currentOffset = new AtomicLong(currentOffset);
}
 
Example 48
Project: talchain   File: Ethash.java   Source Code and License 5 votes vote down vote up
/**
 *  Mines the nonce for the specified Block with difficulty BlockHeader.getDifficulty()
 *  When mined the Block 'nonce' and 'mixHash' fields are updated
 *  Uses the full dataset i.e. it faster but takes > 1Gb of memory and may
 *  take up to 10 mins for starting up (depending on whether the dataset was cached)
 *
 *  @param block The block to mine. The difficulty is taken from the block header
 *               This block is updated when mined
 *  @param nThreads CPU threads to mine on
 *  @return the task which may be cancelled. On success returns nonce
 */
public ListenableFuture<MiningResult> mine(final Block block, int nThreads) {
    return new MineTask(block, nThreads,  new Callable<MiningResult>() {
        AtomicLong taskStartNonce = new AtomicLong(startNonce >= 0 ? startNonce : new Random().nextLong());
        @Override
        public MiningResult call() throws Exception {
            long threadStartNonce = taskStartNonce.getAndAdd(0x100000000L);
            long nonce = getEthashAlgo().mine(getFullSize(), getFullDataset(),
                    HashUtil.sha3(block.getHeader().getEncodedWithoutNonce()),
                    ByteUtil.byteArrayToLong(block.getHeader().getDifficulty()), threadStartNonce);
            final Pair<byte[], byte[]> pair = hashimotoLight(block.getHeader(), nonce);
            return new MiningResult(nonce, pair.getLeft(), block);
        }
    }).submit();
}
 
Example 49
Project: openjdk-jdk10   File: LongAdderDemo.java   Source Code and License 5 votes vote down vote up
static void casTest(int nthreads, int incs) {
    System.out.print("AtomicLong ");
    Phaser phaser = new Phaser(nthreads + 1);
    AtomicLong a = new AtomicLong();
    for (int i = 0; i < nthreads; ++i)
        pool.execute(new CasTask(a, phaser, incs));
    report(nthreads, incs, timeTasks(phaser), a.get());
}
 
Example 50
Project: openjdk-jdk10   File: Test7009231.java   Source Code and License 5 votes vote down vote up
protected void clearBit(AtomicLong atomic, long lMask) {
    long lWord;
    do {
        lWord = atomic.get();
    } while (!atomic.compareAndSet(lWord, lWord & ~lMask));

    if ((atomic.get() & lMask) != 0L) {
        throw new InternalError();
    }
}
 
Example 51
Project: fluid   File: KafkaUsage.java   Source Code and License 5 votes vote down vote up
public void consumeStrings(String topicName, int count, long timeout, TimeUnit unit, Runnable completion, BiPredicate<String, String> consumer) {
    AtomicLong readCounter = new AtomicLong();
    this.consumeStrings(this.continueIfNotExpired(() -> {
        return readCounter.get() < (long) count;
    }, timeout, unit), completion, Collections.singleton(topicName), (record) -> {
        if (consumer.test(record.key(), record.value())) {
            readCounter.incrementAndGet();
        }

    });
}
 
Example 52
Project: AndroidUtilCode-master   File: CacheUtils.java   Source Code and License 5 votes vote down vote up
private CacheManager(File cacheDir, long sizeLimit, int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    calculateCacheSizeAndCacheCount();
}
 
Example 53
Project: MyFire   File: ACache.java   Source Code and License 5 votes vote down vote up
private ACacheManager(File cacheDir, long sizeLimit, int countLimit) {
    this.cacheDir = cacheDir;
    this.sizeLimit = sizeLimit;
    this.countLimit = countLimit;
    cacheSize = new AtomicLong();
    cacheCount = new AtomicInteger();
    calculateCacheSizeAndCacheCount();
}
 
Example 54
Project: openjdk-jdk10   File: AtomicLongTest.java   Source Code and License 5 votes vote down vote up
/**
 * getAndIncrement returns previous value and increments
 */
public void testGetAndIncrement() {
    AtomicLong ai = new AtomicLong(1);
    assertEquals(1, ai.getAndIncrement());
    assertEquals(2, ai.get());
    ai.set(-2);
    assertEquals(-2, ai.getAndIncrement());
    assertEquals(-1, ai.getAndIncrement());
    assertEquals(0, ai.getAndIncrement());
    assertEquals(1, ai.get());
}
 
Example 55
Project: ditb   File: ServerSideScanMetrics.java   Source Code and License 5 votes vote down vote up
/**
 * @param counterName
 * @param value
 */
public void setCounter(String counterName, long value) {
  AtomicLong c = this.counters.get(counterName);
  if (c != null) {
    c.set(value);
  }
}
 
Example 56
Project: EatDubbo   File: AbstractClusterInvokerTest.java   Source Code and License 5 votes vote down vote up
/**
     * 测试均衡.
     */
    @Test
    public void testSelectBalance(){
        
        LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME);
        initlistsize5();
        
        Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
        for(Invoker invoker :invokers){
            counter.put(invoker, new AtomicLong(0));
        }
        int runs = 1000;
        for(int i=0;i<runs;i++){
            selectedInvokers.clear();
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            counter.get(sinvoker).incrementAndGet();
        }
        
        for (Invoker minvoker :counter.keySet() ){
            Long count = counter.get(minvoker).get();
//            System.out.println(count);
            if(minvoker.isAvailable())
                Assert.assertTrue("count should > avg", count>runs/invokers.size());
        }
        
        Assert.assertEquals(runs, counter.get(invoker2).get()+counter.get(invoker4).get());;
        
    }
 
Example 57
Project: dubbox-hystrix   File: LoadBalanceTest.java   Source Code and License 5 votes vote down vote up
public Map<Invoker,AtomicLong> getInvokeCounter(int runs,String loadbalanceName) {
    Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(loadbalanceName);
    for(Invoker invoker :invokers){
        counter.put(invoker, new AtomicLong(0));
    }
    for(int i=0;i<runs;i++){
        Invoker sinvoker = lb.select(invokers, invokers.get(0).getUrl(), invocation);
        counter.get(sinvoker).incrementAndGet();
    }
    return counter;
}
 
Example 58
Project: hadoop-oss   File: DecayRpcScheduler.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
public Map<Object, Long> getCallCountSnapshot() {
  HashMap<Object, Long> snapshot = new HashMap<Object, Long>();

  for (Map.Entry<Object, AtomicLong> entry : callCounts.entrySet()) {
    snapshot.put(entry.getKey(), entry.getValue().get());
  }

  return Collections.unmodifiableMap(snapshot);
}
 
Example 59
Project: elasticsearch_my   File: PrioritizedRunnableTests.java   Source Code and License 5 votes vote down vote up
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());
}
 
Example 60
Project: openjdk-jdk10   File: Collection8Test.java   Source Code and License 5 votes vote down vote up
/**
 * stream().forEach returns elements in the collection
 */
public void testStreamForEach() throws Throwable {
    final Collection c = impl.emptyCollection();
    final AtomicLong count = new AtomicLong(0L);
    final Object x = impl.makeElement(1);
    final Object y = impl.makeElement(2);
    final ArrayList found = new ArrayList();
    Consumer<Object> spy = o -> found.add(o);
    c.stream().forEach(spy);
    assertTrue(found.isEmpty());

    assertTrue(c.add(x));
    c.stream().forEach(spy);
    assertEquals(Collections.singletonList(x), found);
    found.clear();

    assertTrue(c.add(y));
    c.stream().forEach(spy);
    assertEquals(2, found.size());
    assertTrue(found.contains(x));
    assertTrue(found.contains(y));
    found.clear();

    c.clear();
    c.stream().forEach(spy);
    assertTrue(found.isEmpty());
}