use of java.util.concurrent.ScheduledExecutorService in project lucene-solr by apache.
the class CdcrReplicationHandlerTest method testReplicationWithBufferedUpdates.
/**
* Test the scenario where the slave is killed while the leader is still receiving updates.
* The slave should buffer updates while in recovery, then replay them at the end of the recovery.
* If updates were properly buffered and replayed, then the slave should have the same number of documents
* than the leader. This checks if cdcr tlog replication interferes with buffered updates - SOLR-8263.
*/
@Test
@ShardsFixed(num = 2)
public void testReplicationWithBufferedUpdates() throws Exception {
List<CloudJettyRunner> slaves = this.getShardToSlaveJetty(SOURCE_COLLECTION, SHARD1);
AtomicInteger numDocs = new AtomicInteger(0);
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new DefaultSolrThreadFactory("cdcr-test-update-scheduler"));
executor.scheduleWithFixedDelay(new UpdateThread(numDocs), 10, 10, TimeUnit.MILLISECONDS);
// Restart the slave node to trigger Replication strategy
this.restartServer(slaves.get(0));
// shutdown the update thread and wait for its completion
executor.shutdown();
executor.awaitTermination(500, TimeUnit.MILLISECONDS);
// check that we have the expected number of documents in the cluster
assertNumDocs(numDocs.get(), SOURCE_COLLECTION);
// check that we have the expected number of documents on the slave
assertNumDocs(numDocs.get(), slaves.get(0));
}
use of java.util.concurrent.ScheduledExecutorService in project lucene-solr by apache.
the class LeaderElectionTest method testStressElection.
@Test
public void testStressElection() throws Exception {
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(15, new DefaultSolrThreadFactory("stressElection"));
final List<ClientThread> threads = Collections.synchronizedList(new ArrayList<ClientThread>());
// start with a leader
ClientThread thread1 = null;
thread1 = new ClientThread("shard1", 0);
threads.add(thread1);
scheduler.schedule(thread1, 0, TimeUnit.MILLISECONDS);
Thread.sleep(2000);
Thread scheduleThread = new Thread() {
@Override
public void run() {
int count = atLeast(5);
for (int i = 1; i < count; i++) {
int launchIn = random().nextInt(500);
ClientThread thread = null;
try {
thread = new ClientThread("shard1", i);
} catch (Exception e) {
//
}
if (thread != null) {
threads.add(thread);
scheduler.schedule(thread, launchIn, TimeUnit.MILLISECONDS);
}
}
}
};
Thread killThread = new Thread() {
@Override
public void run() {
while (!stopStress) {
try {
int j;
try {
// always 1 we won't kill...
j = random().nextInt(threads.size() - 2);
} catch (IllegalArgumentException e) {
continue;
}
try {
threads.get(j).close();
} catch (Exception e) {
}
Thread.sleep(10);
} catch (Exception e) {
}
}
}
};
Thread connLossThread = new Thread() {
@Override
public void run() {
while (!stopStress) {
try {
Thread.sleep(50);
int j;
j = random().nextInt(threads.size());
try {
threads.get(j).es.zkClient.getSolrZooKeeper().closeCnxn();
if (random().nextBoolean()) {
long sessionId = zkClient.getSolrZooKeeper().getSessionId();
server.expire(sessionId);
}
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep(500);
} catch (Exception e) {
}
}
}
};
scheduleThread.start();
connLossThread.start();
killThread.start();
Thread.sleep(4000);
stopStress = true;
scheduleThread.interrupt();
connLossThread.interrupt();
killThread.interrupt();
scheduleThread.join();
scheduler.shutdownNow();
connLossThread.join();
killThread.join();
int seq = threads.get(getLeaderThread()).getSeq();
// cleanup any threads still running
for (ClientThread thread : threads) {
thread.es.zkClient.getSolrZooKeeper().close();
thread.close();
}
for (Thread thread : threads) {
thread.join();
}
}
use of java.util.concurrent.ScheduledExecutorService in project lucene-solr by apache.
the class ConnectionManagerTest method testReconnectWhenZkDisappeared.
@Test
public void testReconnectWhenZkDisappeared() throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new DefaultSolrThreadFactory("connectionManagerTest"));
// setup a SolrZkClient to do some getBaseUrlForNodeName testing
String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
ZkTestServer server = new ZkTestServer(zkDir);
try {
server.run();
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
MockZkClientConnectionStrategy strat = new MockZkClientConnectionStrategy();
SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, strat, null);
ConnectionManager cm = zkClient.getConnectionManager();
try {
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
// reconnect -- should no longer be likely expired
cm.process(new WatchedEvent(EventType.None, KeeperState.Expired, ""));
assertFalse(cm.isLikelyExpired());
assertTrue(cm.isConnected());
assertTrue(strat.isExceptionThrow());
} finally {
cm.close();
zkClient.close();
executor.shutdown();
}
} finally {
server.shutdown();
}
}
use of java.util.concurrent.ScheduledExecutorService in project geode by apache.
the class OneTaskOnlyDecoratorJUnitTest method testExecuteOnlyOnce.
/**
* Test to make sure we only execute the task once no matter how many times we schedule it.
*/
@Test
public void testExecuteOnlyOnce() throws Exception {
ScheduledExecutorService ex = Executors.newScheduledThreadPool(1);
MyConflationListener listener = new MyConflationListener();
OneTaskOnlyExecutor decorator = new OneTaskOnlyExecutor(ex, listener);
final CountDownLatch latch = new CountDownLatch(1);
ex.submit(new Callable() {
public Object call() throws Exception {
latch.await();
return null;
}
});
final AtomicInteger counter = new AtomicInteger();
Runnable increment = new Runnable() {
public void run() {
counter.incrementAndGet();
}
};
for (int i = 0; i < 50; i++) {
decorator.schedule(increment, 0, TimeUnit.SECONDS);
}
assertEquals(0, counter.get());
latch.countDown();
ex.shutdown();
ex.awaitTermination(60, TimeUnit.SECONDS);
assertEquals(1, counter.get());
assertEquals(49, listener.getDropCount());
}
use of java.util.concurrent.ScheduledExecutorService in project jackrabbit-oak by apache.
the class CompactionAndCleanupIT method offlineCompactionBinC1.
@Test
public void offlineCompactionBinC1() throws Exception {
SegmentGCOptions gcOptions = defaultGCOptions().setOffline().withBinaryDeduplication();
ScheduledExecutorService executor = newSingleThreadScheduledExecutor();
FileStore fileStore = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withGCOptions(gcOptions).withStatisticsProvider(new DefaultStatisticsProvider(executor)).build();
SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
try {
NodeBuilder extra = nodeStore.getRoot().builder();
NodeBuilder content = extra.child("content");
int blobSize = 5 * 1024 * 1024;
byte[] data = new byte[blobSize];
new Random().nextBytes(data);
NodeBuilder c1 = content.child("c1");
Blob b1 = nodeStore.createBlob(new ByteArrayInputStream(data));
c1.setProperty("blob1", b1);
NodeBuilder c2 = content.child("c2");
Blob b2 = nodeStore.createBlob(new ByteArrayInputStream(data));
c2.setProperty("blob2", b2);
nodeStore.merge(extra, EmptyHook.INSTANCE, CommitInfo.EMPTY);
fileStore.flush();
int cpNo = 4;
Set<String> cps = new HashSet<String>();
for (int i = 0; i < cpNo; i++) {
cps.add(nodeStore.checkpoint(60000));
}
assertEquals(cpNo, cps.size());
for (String cp : cps) {
assertTrue(nodeStore.retrieve(cp) != null);
}
long size1 = fileStore.getStats().getApproximateSize();
fileStore.compact();
fileStore.cleanup();
long size2 = fileStore.getStats().getApproximateSize();
assertSize("with compacted binaries", size2, 0, size1 - blobSize);
} finally {
fileStore.close();
}
}
Aggregations