use of javax.cache.configuration.Factory in project ignite by apache.
the class CacheContinuousQueryFilterDeploymentFailedTest method testContinuousQueryFilterDeploymentFailed.
/**
* Tests continuous query behavior in case of filter deployment obtaining failure.
*
* @throws Exception If failed.
*/
@Test
@SuppressWarnings({ "ThrowableNotThrown" })
public void testContinuousQueryFilterDeploymentFailed() throws Exception {
startGrids(NODES_CNT - 1);
IgniteEx cli = startClientGrid(NODES_CNT - 1);
IgniteCache<Integer, Integer> cache = cli.createCache(DEFAULT_CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
Class<Factory<CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
qry.setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDeploymentRequest);
assertThrowsWithCause(() -> cache.query(qry), CacheException.class);
assertTrue(stopRoutineLatch.await(getTestTimeout(), MILLISECONDS));
assertTrue(allGrids().stream().allMatch(g -> ((IgniteEx) g).context().systemView().view(CQ_SYS_VIEW).size() == 0));
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToNewClient.
/**
* Test starts 1 server node and 1 client node. The client node deploys
* CQ for the cache {@link #CACHE_NAME}. After that another client node is started.
* Expected that CQ won't be deployed to the new client, since the client doesn't
* store any data.
*
* @throws Exception If failed.
*/
@Test
public void testDeploymentToNewClient() throws Exception {
startGrid(0);
IgniteEx client1 = startClientGrid(1);
IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
cache.query(qry);
IgniteEx client2 = startClientGrid(2);
GridContinuousProcessor proc = client2.context().continuous();
assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToExistingClient.
/**
* Test starts 1 server node and 2 client nodes. The first client node deploys
* CQ for the cache {@link #CACHE_NAME}.
* Expected that CQ won't be deployed to the second client, since the client doesn't
* store any data.
*
* @throws Exception If failed.
*/
@Test
public void testDeploymentToExistingClient() throws Exception {
startGrid(0);
IgniteEx client1 = startClientGrid(1);
IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
IgniteEx client2 = startClientGrid(2);
AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
cache.query(qry);
GridContinuousProcessor proc = client2.context().continuous();
assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
use of javax.cache.configuration.Factory in project Payara by payara.
the class CompleteConfigurationProxy method proxyWriter.
private Factory<CacheWriter<? super K, ? super V>> proxyWriter(final Factory<CacheWriter<? super K, ? super V>> fact) {
return new Factory<CacheWriter<? super K, ? super V>>() {
@Override
public CacheWriter<K, V> create() {
@Cleanup Context ctx = ctxUtil.pushContext();
@SuppressWarnings("unchecked") final CacheWriter<K, V> delegate = (CacheWriter<K, V>) fact.create();
return new CacheWriterImpl(delegate);
}
@RequiredArgsConstructor
class CacheWriterImpl implements CacheWriter<K, V> {
@Override
public void write(Cache.Entry<? extends K, ? extends V> entry) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.write(entry);
}
@Override
public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> clctn) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.writeAll(clctn);
}
@Override
public void delete(Object o) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.delete(o);
}
@Override
public void deleteAll(Collection<?> clctn) throws CacheWriterException {
@Cleanup Context context = ctxUtil.pushRequestContext();
delegate.deleteAll(clctn);
}
private final CacheWriter<K, V> delegate;
}
private static final long serialVersionUID = 1L;
};
}
use of javax.cache.configuration.Factory in project ignite by apache.
the class UsingContinuousQueries method remoteTransformerExample.
public static void remoteTransformerExample() {
try (Ignite ignite = Ignition.start()) {
// tag::transformer[]
IgniteCache<Integer, Person> cache = ignite.getOrCreateCache("myCache");
// Create a new continuous query with a transformer.
ContinuousQueryWithTransformer<Integer, Person, String> qry = new ContinuousQueryWithTransformer<>();
// Factory to create transformers.
Factory factory = FactoryBuilder.factoryOf(// Only this field will be sent over to the local listener.
(IgniteClosure<CacheEntryEvent, String>) event -> ((Person) event.getValue()).getName());
qry.setRemoteTransformerFactory(factory);
// Listener that will receive transformed data.
qry.setLocalListener(names -> {
for (String name : names) System.out.println("New person name: " + name);
});
// end::transformer[]
cache.query(qry);
cache.put(1, new Person(1, "Vasya"));
}
}
Aggregations