use of java.util.concurrent.CyclicBarrier in project geode by apache.
the class JarDeployerIntegrationTest method testDeployToInvalidDirectory.
@Test
public void testDeployToInvalidDirectory() throws Exception {
final File alternateDir = new File(temporaryFolder.getRoot(), "JarDeployerDUnit");
alternateDir.delete();
final JarDeployer jarDeployer = new JarDeployer(alternateDir);
final byte[] jarBytes = this.classBuilder.createJarFromName("JarDeployerDUnitDTID");
// Test to verify that deployment fails if the directory doesn't exist.
assertThatThrownBy(() -> {
jarDeployer.deployWithoutRegistering("JarDeployerIntegrationTest.jar", jarBytes);
}).isInstanceOf(IOException.class);
// Test to verify that deployment succeeds if the directory doesn't
// initially exist, but is then created while the JarDeployer is looping
// looking for a valid directory.
final AtomicBoolean isDeployed = new AtomicBoolean(false);
final CyclicBarrier barrier = new CyclicBarrier(2);
Executors.newSingleThreadExecutor().submit(() -> {
barrier.await();
jarDeployer.deployWithoutRegistering("JarDeployerIntegrationTest.jar", jarBytes);
isDeployed.set(true);
return true;
});
barrier.await();
alternateDir.mkdirs();
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> assertThat(isDeployed.get()).isTrue());
}
use of java.util.concurrent.CyclicBarrier in project geode by apache.
the class CountedMapLoopsJUnitTest method main.
public static void main(String[] args) throws Exception {
Class mapClass = null;
if (args.length > 0) {
try {
mapClass = Class.forName(args[0]);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Class " + args[0] + " not found.");
}
} else
mapClass = MAP_CLASS;
if (args.length > 1)
maxThreads = Integer.parseInt(args[1]);
if (args.length > 2)
nkeys = Integer.parseInt(args[2]);
if (args.length > 3)
pinsert = Integer.parseInt(args[3]);
if (args.length > 4)
premove = Integer.parseInt(args[4]);
if (args.length > 5)
nops = Integer.parseInt(args[5]);
// normalize probabilities wrt random number generator
removesPerMaxRandom = (int) (((double) premove / 100.0 * 0x7FFFFFFFL));
insertsPerMaxRandom = (int) (((double) pinsert / 100.0 * 0x7FFFFFFFL));
System.out.print("Class: " + mapClass.getName());
System.out.print(" threads: " + maxThreads);
System.out.print(" size: " + nkeys);
System.out.print(" ins: " + pinsert);
System.out.print(" rem: " + premove);
System.out.print(" ops: " + nops);
System.out.println();
final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
Integer[] key = new Integer[nkeys];
for (int i = 0; i < key.length; ++i) key[i] = new Integer(rng.next());
AtomicInteger counter;
// warmup
System.out.println("Warmup...");
for (int k = 0; k < 2; ++k) {
Map map = (Map) mapClass.newInstance();
counter = new AtomicInteger(0);
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(1, timer);
new Runner(map, key, barrier, counter).run();
int size = map.size();
if (size != counter.get())
throw new Error();
map.clear();
map = null;
Thread.sleep(100);
}
System.gc();
int k = 1;
for (int i = 1; i <= maxThreads; ) {
System.out.print("Threads: " + i + "\t:");
Map map = (Map) mapClass.newInstance();
counter = new AtomicInteger(0);
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(i + 1, timer);
for (int t = 0; t < i; ++t) pool.execute(new Runner(map, key, barrier, counter));
barrier.await();
barrier.await();
long time = timer.getTime();
long tpo = time / (i * (long) nops);
System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
double secs = (double) (time) / 1000000000.0;
System.out.println("\t " + secs + "s run time");
int size = map.size();
if (size != counter.get())
throw new Error();
map.clear();
map = null;
// System.gc();
Thread.sleep(100);
if (i == k) {
k = i << 1;
i = i + (i >>> 1);
} else
i = k;
}
pool.shutdown();
}
use of java.util.concurrent.CyclicBarrier in project geode by apache.
the class StringMapLoopsJUnitTest method test.
static void test(int i, int nkeys, String[] key, Class mapClass) throws Exception {
System.out.print("Threads: " + i + "\t:");
Map map = (Map) mapClass.newInstance();
// Uncomment to start with a non-empty table
// for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
// map.put(key[j], key[j]);
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(i + 1, timer);
for (int t = 0; t < i; ++t) pool.execute(new Runner(t, map, key, barrier));
barrier.await();
barrier.await();
long time = timer.getTime();
long tpo = time / (i * (long) nops);
System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
double secs = (double) (time) / 1000000000.0;
System.out.println("\t " + secs + "s run time");
map.clear();
}
use of java.util.concurrent.CyclicBarrier in project geode by apache.
the class MapLoopsJUnitTest method test.
static void test(int i, int nkeys, Class mapClass) throws Exception {
System.out.print("Threads: " + i + "\t:");
Map map = (Map) mapClass.newInstance();
Integer[] key = makeKeys(nkeys);
// Uncomment to start with a non-empty table
// for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
// map.put(key[j], key[j]);
shuffleKeys(key);
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
CyclicBarrier barrier = new CyclicBarrier(i + 1, timer);
for (int t = 0; t < i; ++t) pool.execute(new Runner(t, map, key, barrier));
barrier.await();
barrier.await();
long time = timer.getTime();
long tpo = time / (i * (long) nops);
System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
double secs = (double) (time) / 1000000000.0;
System.out.println("\t " + secs + "s run time");
map.clear();
}
use of java.util.concurrent.CyclicBarrier in project robovm by robovm.
the class ThreadsTest method test_parkFor_2.
/** Test the case where the unpark happens before the timeout. */
public void test_parkFor_2() throws Exception {
CyclicBarrier barrier = new CyclicBarrier(2);
Parker parker = new Parker(barrier, false, 1000);
Thread parkerThread = new Thread(parker);
Thread waiterThread = new Thread(new WaitAndUnpark(barrier, 300, parkerThread));
parkerThread.start();
waiterThread.start();
parker.assertDurationIsInRange(300);
waiterThread.join();
parkerThread.join();
}
Aggregations