java.util.concurrent.atomic.LongAdder源码实例Demo

类java.util.concurrent.atomic.LongAdder源码实例Demo

下面列出了java.util.concurrent.atomic.LongAdder 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reactor-core   文件: MonoPeekAfterTest.java
@Test
public void onSuccessNormalConditional() {
	LongAdder invoked = new LongAdder();
	AtomicBoolean hasNull = new AtomicBoolean();

	Mono<Integer> mono = Flux
			.range(1, 10)
			.reduce((a, b) -> a + b)
			.hide()
			.filter(v -> true)
			.doOnSuccess(v -> {
				if (v == null) hasNull.set(true);
				invoked.increment();
			});

	StepVerifier.create(mono)
	            .expectFusion(Fuseable.ANY, Fuseable.NONE)
	            .expectNext(55)
	            .expectComplete()
	            .verify();

	assertFalse("unexpected call to onSuccess with null", hasNull.get());
	assertEquals(1, invoked.intValue());

}
 
源代码2 项目: spliceengine   文件: HBaseRollForward.java
public HBaseRollForward(TxnSupplier supplier, SConfiguration config) {

        this.firstQueue = new ArrayBlockingQueue<>(config.getRollforwardQueueSize());
        this.secondQueue = new ArrayBlockingQueue<>(config.getRollforwardQueueSize());
        this.firstThreads = config.getRollforwardFirstThreads();
        this.secondThreads = config.getRollforwardSecondThreads();

        this.serviceFirst = Executors.newFixedThreadPool(firstThreads,
                new ThreadFactoryBuilder().setDaemon(true).setNameFormat("WritesRollforward-%d").build());
        this.serviceSecond = Executors.newFixedThreadPool(secondThreads,
                new ThreadFactoryBuilder().setDaemon(true).setNameFormat("WritesRollforward-retry-%d").build());
        this.supplier = supplier;
        this.firstResolutions = new LongAdder();
        this.secondResolutions = new LongAdder();
        this.firstActive = new LongAdder();
        this.secondActive = new LongAdder();
        this.firstProcessor = new RollForwarder(firstQueue, secondQueue, config.getRollforwardFirstWait(), firstResolutions, firstActive);
        this.secondProcessor = new RollForwarder(secondQueue, null, config.getRollforwardSecondWait(), secondResolutions, secondActive);
    }
 
源代码3 项目: reactor-core   文件: MonoPeekAfterTest.java
@Test
public void onSuccessFusion() {
	LongAdder invoked = new LongAdder();
	AtomicBoolean hasNull = new AtomicBoolean();

	Mono<Integer> mono = Flux
			.range(1, 10)
			.reduce((a, b) -> a + b)
			.doOnSuccess(v -> {
				if (v == null) hasNull.set(true);
				invoked.increment();
			});

	StepVerifier.create(mono)
	            .expectFusion(Fuseable.ASYNC)
	            .expectNext(55)
	            .expectComplete()
	            .verify();

	assertFalse("unexpected call to onSuccess with null", hasNull.get());
	assertEquals(1, invoked.intValue());
}
 
源代码4 项目: tlaplus   文件: SimulationWorkerTest.java
@Test
public void testActionPropertyBadEval() throws Exception {
	ITool tool = new FastTool("", "BasicMultiTrace", "MCActionPropBadEval", new SimpleFilenameToStream());
	
	StateVec initStates = tool.getInitStates();
	ILiveCheck liveCheck =  new NoOpLiveCheck(tool, "BasicMultiTrace");
	BlockingQueue<SimulationWorkerResult> resultQueue = new LinkedBlockingQueue<>();
	SimulationWorker worker = new SimulationWorker(0, tool, initStates, resultQueue, 0, 100, 100, false, null,
			liveCheck, new LongAdder(), new LongAdder());
	worker.start();
	
	SimulationWorkerResult res = resultQueue.take();
	
	assertTrue(res.isError());
	SimulationWorkerError err = res.error();
	assertEquals(EC.TLC_ACTION_PROPERTY_EVALUATION_FAILED, err.errorCode);
			
	worker.join();
	assertFalse(worker.isAlive());
}
 
源代码5 项目: reactor-core   文件: FluxBufferPredicateTest.java
@Test
@SuppressWarnings("unchecked")
public void requestUnboundedFromStartRequestsSourceOnce() {
	LongAdder requestCallCount = new LongAdder();
	LongAdder totalRequest = new LongAdder();
	Flux<Integer> source = Flux.range(1, 10).hide()
	                           .doOnRequest(r -> requestCallCount.increment())
	                           .doOnRequest(totalRequest::add);

	StepVerifier.withVirtualTime(//start with an unbounded request
			() -> new FluxBufferPredicate<>(source, i -> i % 3 == 0,
					Flux.listSupplier(), FluxBufferPredicate.Mode.UNTIL))
	            .expectSubscription()
	            .expectNext(Arrays.asList(1, 2, 3))
	            .expectNext(Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9))
	            .expectNext(Collections.singletonList(10))
	            .expectComplete()
	            .verify();

	assertThat(requestCallCount.intValue()).isEqualTo(1);
	assertThat(totalRequest.longValue()).isEqualTo(Long.MAX_VALUE); //also unbounded
}
 
源代码6 项目: resilience4j   文件: CircuitBreakerMetrics.java
private CircuitBreakerMetrics(int slidingWindowSize,
    CircuitBreakerConfig.SlidingWindowType slidingWindowType,
    CircuitBreakerConfig circuitBreakerConfig,
    Clock clock) {
    if (slidingWindowType == CircuitBreakerConfig.SlidingWindowType.COUNT_BASED) {
        this.metrics = new FixedSizeSlidingWindowMetrics(slidingWindowSize);
        this.minimumNumberOfCalls = Math
            .min(circuitBreakerConfig.getMinimumNumberOfCalls(), slidingWindowSize);
    } else {
        this.metrics = new SlidingTimeWindowMetrics(slidingWindowSize, clock);
        this.minimumNumberOfCalls = circuitBreakerConfig.getMinimumNumberOfCalls();
    }
    this.failureRateThreshold = circuitBreakerConfig.getFailureRateThreshold();
    this.slowCallRateThreshold = circuitBreakerConfig.getSlowCallRateThreshold();
    this.slowCallDurationThresholdInNanos = circuitBreakerConfig.getSlowCallDurationThreshold()
        .toNanos();
    this.numberOfNotPermittedCalls = new LongAdder();
}
 
源代码7 项目: vertx-micrometer-metrics   文件: GaugesTest.java
@Test
public void shouldIgnoreGaugeLabel() {
  MeterRegistry registry = new SimpleMeterRegistry();
  BackendRegistries.registerMatchers(registry, ALL_LABELS, Collections.singletonList(new Match()
    .setLabel("address")
    .setType(MatchType.REGEX)
    .setValue(".*")
    .setAlias("_")));
  Gauges<LongAdder> gauges = new Gauges<>("my_gauge", "", LongAdder::new, LongAdder::doubleValue, registry, Label.EB_ADDRESS);
  gauges.get("addr1").increment();
  gauges.get("addr1").increment();
  gauges.get("addr2").increment();

  Gauge g = registry.find("my_gauge").tags("address", "_").gauge();
  assertThat(g.value()).isEqualTo(3d);
  g = registry.find("my_gauge").tags("address", "addr1").gauge();
  assertThat(g).isNull();
  g = registry.find("my_gauge").tags("address", "addr2").gauge();
  assertThat(g).isNull();
}
 
源代码8 项目: reactor-core   文件: MonoPeekAfterTest.java
@Test
public void onAfterSuccessOrErrorFusion() {
	LongAdder invoked = new LongAdder();
	AtomicBoolean completedEmpty = new AtomicBoolean();
	AtomicReference<Throwable> error = new AtomicReference<>();

	@SuppressWarnings("deprecation")
	Mono<Integer> mono = Flux
			.range(1, 10)
			.reduce((a, b) -> a + b)
			.doAfterSuccessOrError((v, t) -> {
				if (v == null && t == null) completedEmpty.set(true);
				if (t != null) error.set(t);
				invoked.increment();
			});

	StepVerifier.create(mono.log())
	            .expectFusion()
	            .expectNext(55)
	            .expectComplete()
	            .verify();

	assertFalse("unexpected empty completion", completedEmpty.get());
	assertEquals(1, invoked.intValue());
	assertEquals("unexpected error", null, error.get());
}
 
源代码9 项目: jdk-source-analysis   文件: LongAdderTest.java
@Test
public void test() {
    LongAdder adder = new LongAdder();
    int processors = Runtime.getRuntime().availableProcessors();
    System.out.println(processors);
    ExecutorService executor = Executors.newFixedThreadPool(processors);
    for (int i = 0; i < processors - 1; i++) {
        executor.execute(() -> {
            for (int j = 0; j < Integer.MAX_VALUE; j++) {
                adder.increment();
            }
        });
    }
    executor.execute(() -> {
        while (true) {
            try {
                System.out.println(adder.sum());
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    executor.shutdown();
    LockSupport.park();
}
 
源代码10 项目: tlaplus   文件: SimulationWorkerTest.java
@Test
public void testWorkerInterruption() throws Exception {
	ITool tool = new FastTool("", "BasicMultiTrace", "MCInv", new SimpleFilenameToStream());
	
	StateVec initStates = tool.getInitStates();
	ILiveCheck liveCheck =  new NoOpLiveCheck(tool, "BasicMultiTrace");
	BlockingQueue<SimulationWorkerResult> resultQueue = new LinkedBlockingQueue<>();
	
	// If we set the trace limit to the max, the worker should effectively run forever. We verify that after it generates
	// a result, we can cancel it and the worker will terminate.
	long traceNum = Long.MAX_VALUE;
	SimulationWorker worker = new SimulationWorker(0, tool, initStates, resultQueue, 0, 100, traceNum, false, null,
			liveCheck, new LongAdder(), new LongAdder());
	worker.start();
	
	// Check one result.
	SimulationWorkerResult res = resultQueue.take();
	
	assertTrue(res.isError());
	SimulationWorkerError err = res.error();
	assertEquals(EC.TLC_INVARIANT_VIOLATED_BEHAVIOR, err.errorCode);
	assertEquals(3, err.stateTrace.size());
	
	// Cancel the worker.
	worker.interrupt();
	worker.join();
	assertFalse(worker.isAlive());
}
 
源代码11 项目: jdk8u_jdk   文件: SplittableRandomTest.java
/**
 * A parallel unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).parallel().forEach(x -> {counter.increment();});
    assertEquals(counter.sum(), size);
}
 
源代码12 项目: reactor-core   文件: StepVerifierTests.java
@Test
public void cancelOnUnexpectedNextWithMoreData() {
	LongAdder cancelled = new LongAdder();
	assertThatExceptionOfType(AssertionError.class)
			.isThrownBy(() -> StepVerifier.create(Flux.just("foo", "bar")
		                        .doOnCancel(cancelled::increment))
		            .expectNext("baz")
		            .expectComplete()
		            .verify())
	        .withMessageContaining("expected value: baz;");

	assertThat(cancelled.intValue())
			.overridingErrorMessage("the expectNext assertion didn't cause a cancellation")
	        .isEqualTo(1);
}
 
源代码13 项目: ignite   文件: IgfsLocalMetrics.java
/**
 * Adds given numbers to read blocks counters.
 *
 * @param total Total number of blocks read.
 * @param secondary Number of blocks read form secondary FS.
 */
void addReadBlocks(int total, int secondary) {
    IgniteBiTuple<LongAdder, LongAdder> blocksRead0 = blocksRead;

    blocksRead0.get1().add(total);
    blocksRead0.get2().add(secondary);
}
 
源代码14 项目: jdk8u-dev-jdk   文件: RandomTest.java
/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    Random r = new Random();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码15 项目: jdk8u-dev-jdk   文件: SplittableRandomTest.java
/**
 * A sequential unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCountSeq() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).forEach(x -> {counter.increment();});
    assertEquals(counter.sum(), size);
}
 
源代码16 项目: openjdk-8-source   文件: SplittableRandomTest.java
/**
 * A sequential unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCountSeq() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).forEach(x -> {counter.increment();});
    assertEquals(counter.sum(), size);
}
 
源代码17 项目: j2objc   文件: ThreadLocalRandom8Test.java
/**
 * A sequential unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
 
源代码18 项目: openjdk-jdk9   文件: RandomTest.java
/**
 * A sequential sized stream of longs generates the given number of values
 */
public void testLongsCount() {
    LongAdder counter = new LongAdder();
    Random r = new Random();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.longs(size).forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
 
源代码19 项目: MHAP   文件: ClassicCounter.java
@Override
public long getCount(Object obj)
{
	LongAdder adder = map.get(obj);
	if (adder==null)
		return 0;
	
	return map.get(obj).longValue();
}
 
源代码20 项目: Bytecoder   文件: ConcurrentSkipListMap.java
/**
 * Adds to element count, initializing adder if necessary
 *
 * @param c count to add
 */
private void addCount(long c) {
    LongAdder a;
    do {} while ((a = adder) == null &&
                 !ADDER.compareAndSet(this, null, a = new LongAdder()));
    a.add(c);
}
 
源代码21 项目: openjdk-jdk8u   文件: RandomTest.java
/**
 * A sequential sized stream of ints generates the given number of values
 */
public void testIntsCount() {
    LongAdder counter = new LongAdder();
    Random r = new Random();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.ints(size).forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
 
源代码22 项目: dragonwell8_jdk   文件: ThreadLocalRandomTest.java
/**
 * A parallel unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码23 项目: dragonwell8_jdk   文件: ThreadLocalRandomTest.java
/**
 * A sequential unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.ints().limit(size).forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码24 项目: dragonwell8_jdk   文件: ThreadLocalRandomTest.java
/**
 * A sequential unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码25 项目: jdk8u60   文件: ThreadLocalRandomTest.java
/**
 * A parallel unsized stream of longs generates at least 100 values
 */
public void testUnsizedLongsCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.longs().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码26 项目: openjdk-8   文件: SplittableRandomTest.java
/**
 * A parallel unsized stream of longs generates at least 100 values
 */
public void testUnsizedLongsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.longs().limit(size).parallel().forEach(x -> {counter.increment();});
    assertEquals(counter.sum(), size);
}
 
源代码27 项目: jdk8u_jdk   文件: ThreadLocalRandomTest.java
/**
 * A sequential unsized stream of doubles generates at least 100 values
 */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
 
源代码28 项目: openjdk-jdk9   文件: LongAdderTest.java
public void run() {
    try {
        barrier.await();
        LongAdder a = adder;
        for (int i = 0; i < incs; ++i)
            a.add(1L);
        result = a.sum();
        barrier.await();
    } catch (Throwable t) { throw new Error(t); }
}
 
/**
 * A parallel sized stream of ints generates the given number of values
 */
public void testIntsCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.ints(size).parallel().forEach(x -> {
            counter.increment();
        });
        assertEquals(counter.sum(), size);
        size += 524959;
    }
}
 
源代码30 项目: dragonwell8_jdk   文件: SplittableRandomTest.java
/**
 * A parallel unsized stream of ints generates at least 100 values
 */
public void testUnsizedIntsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.ints().limit(size).parallel().forEach(x -> {counter.increment();});
    assertEquals(counter.sum(), size);
}