use of java.util.concurrent.atomic.AtomicIntegerArray in project ignite by apache.
the class IgniteCacheClientQueryReplicatedNodeRestartSelfTest method testRestarts.
/**
* @throws Exception If failed.
*/
public void testRestarts() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-7946");
int duration = 90 * 1000;
int qryThreadNum = 5;
// 2 of 4 data nodes
int restartThreadsNum = 2;
final int nodeLifeTime = 2 * 1000;
final int logFreq = 10;
startGridsMultiThreaded(GRID_CNT);
// The last is client only.
final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT - 1);
fillCaches();
final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(QRY)).getAll();
Thread.sleep(3000);
assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(QRY)).getAll());
assertFalse(pRes.isEmpty());
final AtomicInteger qryCnt = new AtomicInteger();
final AtomicBoolean qrysDone = new AtomicBoolean();
final List<Integer> cacheSize = new ArrayList<>(4);
for (int i = 0; i < GRID_CNT - 1; i++) {
int j = 0;
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
IgniteCache<?, ?> cache = grid(i).cache(cacheName);
assertClient(cache, false);
if (i == 0)
cacheSize.add(cache.size());
else
assertEquals(cacheSize.get(j++).intValue(), cache.size());
}
}
int j = 0;
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
IgniteCache<?, ?> cache = grid(GRID_CNT - 1).cache(cacheName);
assertClient(cache, true);
assertEquals(cacheSize.get(j++).intValue(), cache.size());
}
final IgniteCache<?, ?> clientCache = grid(GRID_CNT - 1).cache("pu");
IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
GridRandom rnd = new GridRandom();
while (!qrysDone.get()) {
SqlFieldsQuery qry = new SqlFieldsQuery(QRY);
boolean smallPageSize = rnd.nextBoolean();
if (smallPageSize)
qry.setPageSize(3);
List<List<?>> res;
try {
res = clientCache.query(qry).getAll();
} catch (CacheException e) {
assertTrue("On large page size must retry.", smallPageSize);
boolean failedOnRemoteFetch = false;
for (Throwable th = e; th != null; th = th.getCause()) {
if (!(th instanceof CacheException))
continue;
if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
failedOnRemoteFetch = true;
break;
}
}
if (!failedOnRemoteFetch) {
e.printStackTrace();
fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
}
res = FAKE;
}
if (res != FAKE && !res.equals(pRes)) {
int j = 0;
// Check for data loss.
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
assertEquals(cacheName, cacheSize.get(j++).intValue(), grid(GRID_CNT - 1).cache(cacheName).size());
}
// Fail with nice message.
assertEquals(pRes, res);
}
int c = qryCnt.incrementAndGet();
if (c % logFreq == 0)
info("Executed queries: " + c);
}
}
}, qryThreadNum, "query-thread");
final AtomicInteger restartCnt = new AtomicInteger();
final AtomicBoolean restartsDone = new AtomicBoolean();
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@SuppressWarnings({ "BusyWait" })
@Override
public Object call() throws Exception {
GridRandom rnd = new GridRandom();
while (!restartsDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, -1));
log.info("Stop node: " + g);
stopGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
log.info("Start node: " + g);
startGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
locks.set(g, 0);
int c = restartCnt.incrementAndGet();
if (c % logFreq == 0)
info("Node restarts: " + c);
}
return true;
}
}, restartThreadsNum, "restart-thread");
Thread.sleep(duration);
info("Stopping..");
restartsDone.set(true);
fut2.get();
info("Restarts stopped.");
qrysDone.set(true);
fut1.get();
info("Queries stopped.");
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_browser_Browser method test_evaluate_array_numbers.
/**
* Test the evaluate() api that returns an array of numbers. Functionality based on Snippet308.
* Only wait till success. Otherwise timeout after 3 seconds.
*/
@Test
public void test_evaluate_array_numbers() {
// Bug 509411
assumeFalse(webkit1SkipMsg(), isWebkit1);
// Small note:
// evaluate() returns 'Double' type. Java doesn't have AtomicDouble
// for convienience we simply convert double to int as we're dealing with integers anyway.
final AtomicIntegerArray atomicIntArray = new AtomicIntegerArray(3);
atomicIntArray.set(0, -1);
browser.addProgressListener(completedAdapter(event -> {
Object[] evalResult = (Object[]) browser.evaluate("return new Array(1,2,3)");
atomicIntArray.set(0, ((Double) evalResult[0]).intValue());
atomicIntArray.set(1, ((Double) evalResult[1]).intValue());
atomicIntArray.set(2, ((Double) evalResult[2]).intValue());
if (debug_verbose_output)
System.out.println("Node value: " + evalResult);
}));
browser.setText("<html><body><p id='myid'>HelloWorld</p></body></html>");
shell.open();
AtomicReference<String> additionalErrorInfo = new AtomicReference<>("");
boolean passed = waitForPassCondition(() -> {
if (atomicIntArray.get(0) != -1) {
if (atomicIntArray.get(0) == 1 && atomicIntArray.get(1) == 2 && atomicIntArray.get(2) == 3) {
return true;
} else {
additionalErrorInfo.set("Resulting numbers in the array are not as expected");
}
}
return false;
});
String message = "".equals(additionalErrorInfo.get()) ? "Javascript did not call java" : "Javasscript called java, but passed wrong values: " + additionalErrorInfo.get();
assertTrue(message, passed);
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project athenz by yahoo.
the class ZpeMetric method increment.
// to increment a metric counter by 1
public void increment(String metricName, String domainName) {
if (statsEnabled) {
if (!counter.containsKey(domainName)) {
counter.putIfAbsent(domainName, new AtomicIntegerArray(DomainMetricType.LOAD_DOMAIN_GOOD.ordinal() + 1));
}
Integer index = com.yahoo.athenz.zts.DomainMetricType.valueOf(metricName).ordinal();
counter.get(domainName).incrementAndGet(index);
}
}
Aggregations