use of org.apache.ignite.client.Person in project ignite by apache.
the class CacheAsyncTest method testGetAsyncReportsCorrectIgniteFutureStates.
/**
* Tests IgniteClientFuture state transitions with getAsync.
* <p>
* - Start an async operation
* - Check that IgniteFuture is not done initially
* - Wait for operation completion
* - Verify that listener callback has been called
* - Verify that operation result is correct
*/
@Test
public void testGetAsyncReportsCorrectIgniteFutureStates() throws Exception {
Person val = new Person(1, Integer.toString(1));
personCache.put(1, val);
IgniteClientFuture<Person> fut = personCache.getAsync(1);
assertFalse(fut.isDone());
AtomicReference<String> completionThreadName = new AtomicReference<>();
fut.thenRun(() -> completionThreadName.set(Thread.currentThread().getName()));
Person res = fut.get();
assertEquals("1", res.getName());
assertTrue(fut.isDone());
assertTrue(GridTestUtils.waitForCondition(() -> completionThreadName.get() != null, TIMEOUT));
assertFalse("Async operation should not complete on thin client listener thread", completionThreadName.get().startsWith("thin-client-channel"));
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class ServicesTest method checkOverloadedMethods.
/**
* @param svc Service.
*/
private void checkOverloadedMethods(TestServiceInterface svc) {
assertEquals("testMethod()", svc.testMethod());
assertEquals("testMethod(String val): test", svc.testMethod("test"));
assertEquals(123, svc.testMethod(123));
assertEquals("testMethod(Object val): test", svc.testMethod(new StringBuilder("test")));
assertEquals("testMethod(String val): null", svc.testMethod((String) null));
assertEquals("testMethod(Object val): null", svc.testMethod((Object) null));
Person person1 = new Person(1, "Person 1");
Person person2 = new Person(2, "Person 2");
assertEquals("testMethod(Person person, Object obj): " + person1 + ", " + person2, svc.testMethod(person1, (Object) person2));
assertEquals("testMethod(Object obj, Person person): " + person1 + ", " + person2, svc.testMethod((Object) person1, person2));
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method testNotPersistRenamingIndexRootPage.
/**
* Checking that if we rename the index root pages without a checkpoint,
* then after restarting the node we will not find them.
*
* @throws Exception If failed.
*/
@Test
public void testNotPersistRenamingIndexRootPage() 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();
assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
stopGrid(0);
n = startGrid(0);
cache = n.cache(DEFAULT_CACHE_NAME);
assertExistIndexRoot(cache, oldTreeName, segments, true);
assertExistIndexRoot(cache, newTreeName, segments, false);
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method testRenamingIndexRootPage.
/**
* Checking the correct renaming of the index root pages.
*
* @throws Exception If failed.
*/
@Test
public void testRenamingIndexRootPage() 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));
int segments = idxDef.segments();
String oldTreeName = idxDef.treeName();
assertExistIndexRoot(cache, oldTreeName, segments, true);
String newTreeName = UUID.randomUUID().toString();
// There will be no renaming.
assertExistIndexRoot(cache, newTreeName, segments, false);
assertTrue(renameIndexRoot(cache, newTreeName, newTreeName, segments).isEmpty());
// Checking the validation of the new index name.
String moreMaxLenName = Arrays.toString(new byte[MAX_IDX_NAME_LEN + 1]);
assertThrows(log, () -> renameIndexRoot(cache, oldTreeName, moreMaxLenName, segments), Exception.class, null);
assertEquals(segments, renameIndexRoot(cache, oldTreeName, newTreeName, segments).size());
assertExistIndexRoot(cache, oldTreeName, segments, false);
assertExistIndexRoot(cache, newTreeName, segments, true);
}
use of org.apache.ignite.client.Person in project ignite by apache.
the class RenameIndexTreeTest method testRenameFromTask.
/**
* Checking the correctness of {@link DurableBackgroundCleanupIndexTreeTaskV2#findIndexRootPages}
* and {@link DurableBackgroundCleanupIndexTreeTaskV2#renameIndexRootPages}.
*
* @throws Exception If failed.
*/
@Test
public void testRenameFromTask() 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));
GridCacheContext<Integer, Person> cctx = cacheContext(cache);
String oldTreeName = idxDef.treeName();
int segments = idxDef.segments();
assertExistIndexRoot(cache, oldTreeName, segments, true);
Map<Integer, RootPage> rootPages0 = findIndexRoots(cache, oldTreeName, segments);
Map<Integer, RootPage> rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments);
assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
long currSegIdx = walMgr(n).currentSegment();
String newTreeName = UUID.randomUUID().toString();
renameIndexRootPages(cctx.group(), cctx.name(), oldTreeName, newTreeName, segments);
assertExistIndexRoot(cache, oldTreeName, segments, false);
assertExistIndexRoot(cache, newTreeName, segments, true);
assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
rootPages0 = findIndexRoots(cache, newTreeName, segments);
rootPages1 = findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments);
assertEqualsCollections(toPageIds(rootPages0), toPageIds(rootPages1));
WALPointer start = new WALPointer(currSegIdx, 0, 0);
IgniteBiPredicate<WALRecord.RecordType, WALPointer> pred = (t, p) -> t == INDEX_ROOT_PAGE_RENAME_RECORD;
try (WALIterator it = walMgr(n).replay(start, pred)) {
List<WALRecord> records = stream(it.spliterator(), false).map(IgniteBiTuple::get2).collect(toList());
assertEquals(1, records.size());
IndexRenameRootPageRecord record = (IndexRenameRootPageRecord) records.get(0);
assertEquals(cctx.cacheId(), record.cacheId());
assertEquals(oldTreeName, record.oldTreeName());
assertEquals(newTreeName, record.newTreeName());
assertEquals(segments, record.segments());
}
}
Aggregations