use of java.util.concurrent.BlockingQueue in project linuxtools by eclipse.
the class ImageTagSelectionPage method searchTags.
private void searchTags() {
try {
final BlockingQueue<List<DockerImageTagSearchResult>> searchResultQueue = new ArrayBlockingQueue<>(1);
ImageTagSelectionPage.this.getContainer().run(true, true, monitor -> {
monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.searchTask"), 2);
final String selectedImageName = ImageTagSelectionPage.this.model.getSelectedImage().getName();
try {
final List<IRepositoryTag> repositoryTags = registry.getTags(selectedImageName);
// we have to convert to list of RepositoryTag which
// can be sorted
final List<RepositoryTag> tags = repositoryTags.stream().map(c -> (RepositoryTag) c).collect(Collectors.toList());
Collections.sort(tags);
monitor.worked(1);
final IDockerConnection connection = model.getSelectedConnection();
final List<DockerImageTagSearchResult> searchResults = repositoryTags.stream().map(t -> new DockerImageTagSearchResult(selectedImageName, t, connection.hasImage(selectedImageName, t.getName()))).collect(Collectors.toList());
monitor.worked(1);
searchResultQueue.offer(searchResults);
} catch (DockerException e) {
} finally {
monitor.done();
}
});
List<DockerImageTagSearchResult> res = searchResultQueue.poll(10, TimeUnit.SECONDS);
final List<DockerImageTagSearchResult> searchResult = (res == null) ? new ArrayList<>() : res;
Display.getCurrent().asyncExec(() -> {
ImageTagSelectionPage.this.model.setImageTagSearchResult(searchResult);
// refresh the wizard buttons
getWizard().getContainer().updateButtons();
});
// display a warning in the title area if the search result is empty
if (searchResult.isEmpty()) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.noTagWarning"), WARNING);
} else if (searchResult.size() == 1) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.oneTagMatched"), INFORMATION);
} else {
this.setMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
"ImageTagSelectionPage.tagsMatched", Integer.toString(searchResult.size())), INFORMATION);
}
} catch (InvocationTargetException | InterruptedException e) {
Activator.log(e);
}
}
use of java.util.concurrent.BlockingQueue in project ignite by apache.
the class CacheInterceptorPartitionCounterRandomOperationsTest method waitAndCheckEvent.
/**
* @param cache Ignite cache.
* @param partCntrs Partition counters.
* @param aff Affinity function.
* @param key Key.
* @param val Value.
* @param oldVal Old value.
* @param rmv Remove operation.
* @throws Exception If failed.
*/
private void waitAndCheckEvent(IgniteCache<Object, Object> cache, Map<Integer, Long> partCntrs, Affinity<Object> aff, Object key, Object val, Object oldVal, boolean rmv) throws Exception {
Collection<BlockingQueue<Cache.Entry<TestKey, TestValue>>> entries = getInterceptorQueues(cache, key, rmv);
assert !entries.isEmpty();
if (val == null && oldVal == null) {
checkNoEvent(entries);
return;
}
for (BlockingQueue<Cache.Entry<TestKey, TestValue>> evtsQueue : entries) {
Cache.Entry<TestKey, TestValue> entry = evtsQueue.poll(5, SECONDS);
assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', entry);
assertEquals(key, entry.getKey());
assertEquals(rmv ? oldVal : val, entry.getValue());
long cntr = partCntrs.get(aff.partition(key));
CacheInterceptorEntry interceptorEntry = entry.unwrap(CacheInterceptorEntry.class);
assertNotNull(cntr);
assertNotNull(interceptorEntry);
assertEquals(cntr, interceptorEntry.getPartitionUpdateCounter());
assertNull(evtsQueue.peek());
}
}
use of java.util.concurrent.BlockingQueue in project ignite by apache.
the class CacheContinuousQueryFactoryFilterRandomOperationTest method doTestContinuousQuery.
/**
* {@inheritDoc}
*/
@Override
protected void doTestContinuousQuery(CacheConfiguration<Object, Object> ccfg, ContinuousDeploy deploy) throws Exception {
ignite(0).createCache(ccfg);
try {
long seed = System.currentTimeMillis();
Random rnd = new Random(seed);
log.info("Random seed: " + seed);
List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues = new ArrayList<>();
Collection<QueryCursor<?>> curs = new ArrayList<>();
Collection<T2<Integer, MutableCacheEntryListenerConfiguration>> lsnrCfgs = new ArrayList<>();
if (deploy == CLIENT)
evtsQueues.add(registerListener(ccfg.getName(), NODES - 1, curs, lsnrCfgs, rnd.nextBoolean()));
else if (deploy == SERVER)
evtsQueues.add(registerListener(ccfg.getName(), rnd.nextInt(NODES - 1), curs, lsnrCfgs, rnd.nextBoolean()));
else {
boolean isSync = rnd.nextBoolean();
for (int i = 0; i < NODES - 1; i++) evtsQueues.add(registerListener(ccfg.getName(), i, curs, lsnrCfgs, isSync));
}
ConcurrentMap<Object, Object> expData = new ConcurrentHashMap<>();
Map<Integer, Long> partCntr = new ConcurrentHashMap<>();
try {
for (int i = 0; i < ITERATION_CNT; i++) {
if (i % 10 == 0)
log.info("Iteration: " + i);
for (int idx = 0; idx < NODES; idx++) randomUpdate(rnd, evtsQueues, expData, partCntr, grid(idx).cache(ccfg.getName()));
}
} finally {
for (QueryCursor<?> cur : curs) cur.close();
for (T2<Integer, MutableCacheEntryListenerConfiguration> e : lsnrCfgs) grid(e.get1()).cache(ccfg.getName()).deregisterCacheEntryListener(e.get2());
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
use of java.util.concurrent.BlockingQueue in project ignite by apache.
the class CacheContinuousQueryRandomOperationsTest method doTestContinuousQuery.
/**
* @param ccfg Cache configuration.
* @param deploy The place where continuous query will be started.
* @throws Exception If failed.
*/
protected void doTestContinuousQuery(CacheConfiguration<Object, Object> ccfg, ContinuousDeploy deploy) throws Exception {
ignite(0).createCache(ccfg);
try {
long seed = System.currentTimeMillis();
Random rnd = new Random(seed);
log.info("Random seed: " + seed);
List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues = new ArrayList<>();
Collection<QueryCursor<?>> curs = new ArrayList<>();
if (deploy == CLIENT) {
AbstractContinuousQuery<Object, Object> qry = createQuery();
final BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue = new ArrayBlockingQueue<>(50_000);
if (qry instanceof ContinuousQuery) {
((ContinuousQuery<Object, Object>) qry).setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
for (CacheEntryEvent<?, ?> evt : evts) evtsQueue.add(evt);
}
});
} else if (qry instanceof ContinuousQueryWithTransformer)
initQueryWithTransformer((ContinuousQueryWithTransformer<Object, Object, CacheEntryEvent>) qry, evtsQueue);
else
fail("Unknown query type");
evtsQueues.add(evtsQueue);
QueryCursor<?> cur = grid(getClientIndex()).cache(ccfg.getName()).query(qry);
curs.add(cur);
} else if (deploy == SERVER) {
AbstractContinuousQuery<Object, Object> qry = createQuery();
final BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue = new ArrayBlockingQueue<>(50_000);
if (qry instanceof ContinuousQuery) {
((ContinuousQuery<Object, Object>) qry).setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
for (CacheEntryEvent<?, ?> evt : evts) evtsQueue.add(evt);
}
});
} else if (qry instanceof ContinuousQueryWithTransformer)
initQueryWithTransformer((ContinuousQueryWithTransformer<Object, Object, CacheEntryEvent>) qry, evtsQueue);
else
fail("Unknown query type");
evtsQueues.add(evtsQueue);
QueryCursor<?> cur = grid(rnd.nextInt(getServerNodeCount())).cache(ccfg.getName()).query(qry);
curs.add(cur);
} else {
for (int i = 0; i <= getServerNodeCount(); i++) {
AbstractContinuousQuery<Object, Object> qry = createQuery();
final BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue = new ArrayBlockingQueue<>(50_000);
if (qry instanceof ContinuousQuery) {
((ContinuousQuery<Object, Object>) qry).setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
for (CacheEntryEvent<?, ?> evt : evts) evtsQueue.add(evt);
}
});
} else if (qry instanceof ContinuousQueryWithTransformer)
initQueryWithTransformer((ContinuousQueryWithTransformer<Object, Object, CacheEntryEvent>) qry, evtsQueue);
else
fail("Unknown query type");
evtsQueues.add(evtsQueue);
QueryCursor<?> cur = ignite(i).cache(ccfg.getName()).query(qry);
curs.add(cur);
}
}
ConcurrentMap<Object, Object> expData = new ConcurrentHashMap<>();
Map<Integer, Long> partCntr = new ConcurrentHashMap<>();
try {
for (int i = 0; i < ITERATION_CNT; i++) {
if (i % 20 == 0)
log.info("Iteration: " + i);
for (int idx = 0; idx < getServerNodeCount(); idx++) randomUpdate(rnd, evtsQueues, expData, partCntr, grid(idx).cache(ccfg.getName()));
}
} finally {
for (QueryCursor<?> cur : curs) cur.close();
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
use of java.util.concurrent.BlockingQueue in project pravega by pravega.
the class StreamTransactionMetadataTasksTest method failOverTests.
@Test
public void failOverTests() throws CheckpointStoreException, InterruptedException {
// Create mock writer objects.
EventStreamWriterMock<CommitEvent> commitWriter = new EventStreamWriterMock<>();
EventStreamWriterMock<AbortEvent> abortWriter = new EventStreamWriterMock<>();
EventStreamReader<CommitEvent> commitReader = commitWriter.getReader();
EventStreamReader<AbortEvent> abortReader = abortWriter.getReader();
consumer = new ControllerService(streamStore, hostStore, streamMetadataTasks, txnTasks, segmentHelperMock, executor, null);
// Create test scope and stream.
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scope(SCOPE).streamName(STREAM).scalingPolicy(policy1).build();
Assert.assertEquals(Controller.CreateScopeStatus.Status.SUCCESS, consumer.createScope(SCOPE).join().getStatus());
Assert.assertEquals(Controller.CreateStreamStatus.Status.SUCCESS, streamMetadataTasks.createStream(SCOPE, STREAM, configuration1, System.currentTimeMillis()).join());
// Set up txn task for creating transactions from a failedHost.
StreamTransactionMetadataTasks failedTxnTasks = new StreamTransactionMetadataTasks(streamStore, hostStore, segmentHelperMock, executor, "failedHost", connectionFactory, false, "");
failedTxnTasks.initializeStreamWriters("commitStream", new EventStreamWriterMock<>(), "abortStream", new EventStreamWriterMock<>());
// Create 3 transactions from failedHost.
VersionedTransactionData tx1 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
VersionedTransactionData tx2 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
VersionedTransactionData tx3 = failedTxnTasks.createTxn(SCOPE, STREAM, 10000, 10000, null).join().getKey();
// Ping another txn from failedHost.
UUID txnId = UUID.randomUUID();
streamStore.createTransaction(SCOPE, STREAM, txnId, 10000, 30000, 30000, null, executor).join();
PingTxnStatus pingStatus = failedTxnTasks.pingTxn(SCOPE, STREAM, txnId, 10000, null).join();
VersionedTransactionData tx4 = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
// Validate versions of all txn
Assert.assertEquals(0, tx1.getVersion());
Assert.assertEquals(0, tx2.getVersion());
Assert.assertEquals(0, tx3.getVersion());
Assert.assertEquals(1, tx4.getVersion());
Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
// Validate the txn index.
Assert.assertEquals(1, streamStore.listHostsOwningTxn().join().size());
// Change state of one txn to COMMITTING.
TxnStatus txnStatus2 = streamStore.sealTransaction(SCOPE, STREAM, tx2.getId(), true, Optional.empty(), null, executor).thenApply(AbstractMap.SimpleEntry::getKey).join();
Assert.assertEquals(TxnStatus.COMMITTING, txnStatus2);
// Change state of another txn to ABORTING.
TxnStatus txnStatus3 = streamStore.sealTransaction(SCOPE, STREAM, tx3.getId(), false, Optional.empty(), null, executor).thenApply(AbstractMap.SimpleEntry::getKey).join();
Assert.assertEquals(TxnStatus.ABORTING, txnStatus3);
// Create transaction tasks for sweeping txns from failedHost.
txnTasks = new StreamTransactionMetadataTasks(streamStore, hostStore, segmentHelperMock, executor, "host", connectionFactory, false, "");
TxnSweeper txnSweeper = new TxnSweeper(streamStore, txnTasks, 100, executor);
// Before initializing, txnSweeper.sweepFailedHosts would throw an error
AssertExtensions.assertThrows("IllegalStateException before initialization", txnSweeper.sweepFailedProcesses(() -> Collections.singleton("host")), ex -> ex instanceof IllegalStateException);
// Initialize stream writers.
txnTasks.initializeStreamWriters("commitStream", commitWriter, "abortStream", abortWriter);
// Validate that txnTasks is ready.
assertTrue(txnTasks.isReady());
// Sweep txns that were being managed by failedHost.
txnSweeper.sweepFailedProcesses(() -> Collections.singleton("host")).join();
// Validate that sweeping completes correctly.
Assert.assertEquals(0, streamStore.listHostsOwningTxn().join().size());
Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx1.getId(), null, executor).join());
Assert.assertEquals(TxnStatus.COMMITTING, streamStore.transactionStatus(SCOPE, STREAM, tx2.getId(), null, executor).join());
Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx3.getId(), null, executor).join());
Assert.assertEquals(TxnStatus.ABORTING, streamStore.transactionStatus(SCOPE, STREAM, tx4.getId(), null, executor).join());
// Create commit and abort event processors.
ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);
BlockingQueue<CommitEvent> processedCommitEvents = new LinkedBlockingQueue<>();
BlockingQueue<AbortEvent> processedAbortEvents = new LinkedBlockingQueue<>();
createEventProcessor("commitRG", "commitStream", commitReader, commitWriter, () -> new CommitEventProcessor(streamStore, streamMetadataTasks, hostStore, executor, segmentHelperMock, connectionFactory, processedCommitEvents));
createEventProcessor("abortRG", "abortStream", abortReader, abortWriter, () -> new ConcurrentEventProcessor<>(new AbortRequestHandler(streamStore, streamMetadataTasks, hostStore, executor, segmentHelperMock, connectionFactory, processedAbortEvents), executor));
// Wait until the commit event is processed and ensure that the txn state is COMMITTED.
CommitEvent commitEvent = processedCommitEvents.take();
assertEquals(tx2.getId(), commitEvent.getTxid());
assertEquals(TxnStatus.COMMITTED, streamStore.transactionStatus(SCOPE, STREAM, tx2.getId(), null, executor).join());
// Wait until 3 abort events are processed and ensure that the txn state is ABORTED.
Predicate<AbortEvent> predicate = event -> event.getTxid().equals(tx1.getId()) || event.getTxid().equals(tx3.getId()) || event.getTxid().equals(tx4.getId());
AbortEvent abortEvent1 = processedAbortEvents.take();
assertTrue(predicate.test(abortEvent1));
AbortEvent abortEvent2 = processedAbortEvents.take();
assertTrue(predicate.test(abortEvent2));
AbortEvent abortEvent3 = processedAbortEvents.take();
assertTrue(predicate.test(abortEvent3));
assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx1.getId(), null, executor).join());
assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx3.getId(), null, executor).join());
assertEquals(TxnStatus.ABORTED, streamStore.transactionStatus(SCOPE, STREAM, tx4.getId(), null, executor).join());
}
Aggregations