use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
final CollectionConfiguration colCfg = collectionConfiguration();
colCfg.setCollocated(false);
colCfg.setCacheMode(CacheMode.PARTITIONED);
colCfg.setGroupName("testGroup");
try (final IgniteSet<Integer> set1 = grid(0).set("Set1", colCfg)) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
set1.affinityRun(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
}, IgniteException.class, "Failed to execute affinityRun() for non-collocated set: " + set1.name() + ". This operation is supported only for collocated sets.");
}
colCfg.setCollocated(true);
try (final IgniteSet<Integer> set2 = grid(0).set("Set2", colCfg)) {
set2.add(100);
final String cacheName = cctx(set2).name();
set2.affinityRun(new IgniteRunnable() {
@IgniteInstanceResource
private IgniteEx ignite;
@Override
public void run() {
assertTrue(ignite.cachex(cacheName).affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Set2"));
assertEquals(100, set2.iterator().next().intValue());
}
});
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalInjection.
/**
* @throws Exception If failed.
*/
public void testLocalInjection() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Boolean>> lists = grid().compute().broadcast(new IgniteCallable<List<Boolean>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Boolean> call() throws Exception {
IgniteClosure<Cache.Entry<Integer, Value>, Boolean> transformer = new IgniteClosure<Cache.Entry<Integer, Value>, Boolean>() {
@IgniteInstanceResource
Ignite ignite;
@Override
public Boolean apply(Cache.Entry<Integer, Value> e) {
return ignite != null;
}
};
return ignite.cache("test-cache").query(new ScanQuery<Integer, Value>().setLocal(true), transformer).getAll();
}
});
List<Boolean> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) assertEquals(Boolean.TRUE, res.get(i));
} finally {
cache.destroy();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalKeepBinary.
/**
* @throws Exception If failed.
*/
public void testLocalKeepBinary() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
return e.getValue().field("idx");
}
};
return ignite.cache("test-cache").withKeepBinary().query(new ScanQuery<Integer, BinaryObject>().setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(50, res.size());
Collections.sort(res);
for (int i = 0; i < 50; i++) assertEquals(i * 100, res.get(i).intValue());
} finally {
cache.destroy();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocal.
/**
* @throws Exception If failed.
*/
public void testLocal() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteClosure<Cache.Entry<Integer, Value>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, Value>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, Value> e) {
return e.getValue().idx;
}
};
return ignite.cache("test-cache").query(new ScanQuery<Integer, Value>().setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(50, res.size());
Collections.sort(res);
for (int i = 0; i < 50; i++) assertEquals(i * 100, res.get(i).intValue());
} finally {
cache.destroy();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalKeepBinaryFiltered.
/**
* @throws Exception If failed.
*/
public void testLocalKeepBinaryFiltered() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteBiPredicate<Integer, BinaryObject> filter = new IgniteBiPredicate<Integer, BinaryObject>() {
@Override
public boolean apply(Integer k, BinaryObject v) {
return v.<Integer>field("idx") % 1000 == 0;
}
};
IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
return e.getValue().field("idx");
}
};
return ignite.cache("test-cache").withKeepBinary().query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(5, res.size());
Collections.sort(res);
for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
} finally {
cache.destroy();
}
}
Aggregations