use of org.apache.ignite.client.Person in project ignite by apache.
the class CacheEntryListenersTest method testListenersWithKeepBinary.
/**
* Test continuous queries and JCache entry listeners with keep binary flag.
*/
@Test
public void testListenersWithKeepBinary() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Object, Object> cache1 = client.getOrCreateCache("testListenersWithKB");
ClientCache<Object, Object> cache2 = cache1.withKeepBinary();
ContinuousQueryListener<Object, Object> lsnr1 = new ContinuousQueryListener<>();
ContinuousQueryListener<Object, Object> lsnr2 = new ContinuousQueryListener<>();
cache1.query(new ContinuousQuery<>().setLocalListener(lsnr1));
cache2.query(new ContinuousQuery<>().setLocalListener(lsnr2));
JCacheEntryListener<Object, Object> lsnr3 = new JCacheEntryListener<>();
JCacheEntryListener<Object, Object> lsnr4 = new JCacheEntryListener<>();
cache1.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr3, null, true, false));
cache2.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr4, null, true, false));
Person person1 = new Person(0, "name");
Person person2 = new Person(1, "another name");
cache1.put(0, person1);
lsnr1.assertNextCacheEvent(EventType.CREATED, 0, person1);
lsnr2.assertNextCacheEvent(EventType.CREATED, 0, client.binary().toBinary(person1));
lsnr3.assertNextCacheEvent(EventType.CREATED, 0, person1);
lsnr4.assertNextCacheEvent(EventType.CREATED, 0, client.binary().toBinary(person1));
cache1.put(0, person2);
lsnr1.assertNextCacheEvent(EventType.UPDATED, 0, person2);
lsnr2.assertNextCacheEvent(EventType.UPDATED, 0, client.binary().toBinary(person2));
lsnr3.assertNextCacheEvent(EventType.UPDATED, 0, person2);
lsnr4.assertNextCacheEvent(EventType.UPDATED, 0, client.binary().toBinary(person2));
}
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class ServicesTest method checkCollectionMethods.
/**
* @param svc Service.
*/
private void checkCollectionMethods(TestServiceInterface svc) {
Person person1 = new Person(1, "Person 1");
Person person2 = new Person(2, "Person 2");
Person[] arr = new Person[] { person1, person2 };
assertTrue(Arrays.equals(arr, svc.testArray(arr)));
Collection<Person> col = new HashSet<>(F.asList(person1, person2));
assertEquals(col, svc.testCollection(col));
Map<Integer, Person> map = F.asMap(1, person1, 2, person2);
assertEquals(map, svc.testMap(map));
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method renameIndexRoot.
/**
* Renaming index trees.
*
* @param cache Cache.
* @param oldTreeName Old index tree name.
* @param newTreeName Old index tree name.
* @param segments Segment count.
* @return Root pages of renamed trees.
* @throws Exception If failed.
*/
private Collection<RootPage> renameIndexRoot(IgniteCache<Integer, Person> cache, String oldTreeName, String newTreeName, int segments) throws Exception {
GridCacheContext<Integer, Person> cacheCtx = cacheContext(cache);
List<RootPage> res = new ArrayList<>();
cacheCtx.shared().database().checkpointReadLock();
try {
for (int i = 0; i < segments; i++) {
RootPage rootPage = cacheCtx.offheap().renameRootPageForIndex(cacheCtx.cacheId(), oldTreeName, newTreeName, i);
if (rootPage != null)
res.add(rootPage);
}
} finally {
cacheCtx.shared().database().checkpointReadUnlock();
}
return res;
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method testPersistRenamingIndexRootPage.
/**
* Checking that the renamed index root pages after the checkpoint will be
* correctly restored and found after the node is restarted.
*
* @throws Exception If failed.
*/
@Test
public void testPersistRenamingIndexRootPage() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
String oldTreeName = idxDef.treeName();
String newTreeName = UUID.randomUUID().toString();
int segments = idxDef.segments();
assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
forceCheckpoint();
stopGrid(0);
n = startGrid(0);
cache = n.cache(DEFAULT_CACHE_NAME);
assertExistIndexRoot(cache, oldTreeName, segments, true);
assertExistIndexRoot(cache, newTreeName, segments, true);
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method testIndexRenameRootPageRecord.
/**
* Checking applying {@link IndexRenameRootPageRecord}.
*
* @throws Exception If failed.
*/
@Test
public void testIndexRenameRootPageRecord() throws Exception {
IgniteEx n = startGrid(0);
IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
populate(cache, 100);
String idxName = "IDX0";
createIdx(cache, idxName);
enableCheckpoints(n, getTestIgniteInstanceName(), false);
SortedIndexDefinition idxDef = indexDefinition(index(n, cache, idxName));
String oldTreeName = idxDef.treeName();
String newTreeName = UUID.randomUUID().toString();
int segments = idxDef.segments();
int cacheId = cacheContext(cache).cacheId();
IndexRenameRootPageRecord r = new IndexRenameRootPageRecord(cacheId, oldTreeName, newTreeName, segments);
walMgr(n).log(r);
Set<Integer> cacheIds = n.context().cache().cacheNames().stream().map(CU::cacheId).collect(toSet());
int fakeCacheId = cacheIds.stream().mapToInt(Integer::intValue).sum();
while (cacheIds.contains(fakeCacheId)) fakeCacheId++;
// Check that the node does not crash when trying to apply a logical record with a non-existing cacheId.
walMgr(n).log(new IndexRenameRootPageRecord(fakeCacheId, oldTreeName, newTreeName, segments));
stopGrid(0);
n = startGrid(0);
cache = n.cache(DEFAULT_CACHE_NAME);
assertExistIndexRoot(cache, oldTreeName, segments, false);
assertExistIndexRoot(cache, newTreeName, segments, true);
}
Aggregations