use of java.util.concurrent.atomic.AtomicLong in project storm by apache.
the class Time method simulatedSleepUntilNanos.
private static void simulatedSleepUntilNanos(long targetTimeNanos) throws InterruptedException {
try {
synchronized (sleepTimesLock) {
if (threadSleepTimesNanos == null) {
LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE"));
throw new InterruptedException();
}
threadSleepTimesNanos.put(Thread.currentThread(), new AtomicLong(targetTimeNanos));
}
while (simulatedCurrTimeNanos.get() < targetTimeNanos) {
synchronized (sleepTimesLock) {
if (threadSleepTimesNanos == null) {
LOG.debug("{} is still sleeping after simulated time disabled.", Thread.currentThread(), new RuntimeException("STACK TRACE"));
throw new InterruptedException();
}
}
long autoAdvance = autoAdvanceNanosOnSleep.get();
if (autoAdvance > 0) {
advanceTimeNanos(autoAdvance);
}
Thread.sleep(10);
}
} finally {
synchronized (sleepTimesLock) {
if (simulating.get() && threadSleepTimesNanos != null) {
threadSleepTimesNanos.remove(Thread.currentThread());
}
}
}
}
use of java.util.concurrent.atomic.AtomicLong in project storm by apache.
the class WorkerBackpressureThreadTest method testNormalEvent.
@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);
}
}
use of java.util.concurrent.atomic.AtomicLong in project storm by apache.
the class DisruptorQueueBackpressureTest method testBackPressureCallback.
@Test
public void testBackPressureCallback() throws Exception {
final DisruptorQueue queue = createQueue("testBackPressure", CAPACITY);
queue.setEnableBackpressure(true);
queue.setHighWaterMark(HIGH_WATERMARK);
queue.setLowWaterMark(LOW_WATERMARK);
final AtomicBoolean throttleOn = new AtomicBoolean(false);
// we need to record the cursor because the DisruptorQueue does not update the readPos during batch consuming
final AtomicLong consumerCursor = new AtomicLong(-1);
DisruptorBackpressureCallbackImpl cb = new DisruptorBackpressureCallbackImpl(queue, throttleOn, consumerCursor);
queue.registerBackpressureCallback(cb);
for (int i = 0; i < MESSAGES; i++) {
queue.publish(String.valueOf(i));
}
queue.consumeBatchWhenAvailable(new EventHandler<Object>() {
@Override
public void onEvent(Object o, long l, boolean b) throws Exception {
consumerCursor.set(l);
}
});
Assert.assertEquals("Check the calling time of throttle on. ", queue.getHighWaterMark(), cb.highWaterMarkCalledPopulation);
Assert.assertEquals("Checking the calling time of throttle off. ", queue.getLowWaterMark(), cb.lowWaterMarkCalledPopulation);
}
use of java.util.concurrent.atomic.AtomicLong in project zookeeper by apache.
the class CreateTTLTest method testModifying.
@Test
public void testModifying() throws IOException, KeeperException, InterruptedException {
Stat stat = new Stat();
zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100);
Assert.assertEquals(0, stat.getEphemeralOwner());
final AtomicLong fakeElapsed = new AtomicLong(0);
ContainerManager containerManager = newContainerManager(fakeElapsed);
containerManager.checkContainers();
Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
for (int i = 0; i < 10; ++i) {
fakeElapsed.set(50);
zk.setData("/foo", new byte[i + 1], -1);
containerManager.checkContainers();
Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false));
}
fakeElapsed.set(200);
containerManager.checkContainers();
Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false));
}
use of java.util.concurrent.atomic.AtomicLong in project zookeeper by apache.
the class CreateTTLTest method testMulti.
@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));
}
Aggregations