Search in sources :

Example 11 with Person

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"));
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 12 with Person

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));
}
Also used : Person(org.apache.ignite.client.Person)

Example 13 with Person

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);
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 14 with Person

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);
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 15 with Person

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());
    }
}
Also used : WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) INDEX_ROOT_PAGE_RENAME_RECORD(org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.INDEX_ROOT_PAGE_RENAME_RECORD) Arrays(java.util.Arrays) Person(org.apache.ignite.client.Person) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.findIndexRootPages) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ArrayList(java.util.ArrayList) GridTestUtils.cacheContext(org.apache.ignite.testframework.GridTestUtils.cacheContext) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) Collection(java.util.Collection) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Set(java.util.Set) DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.renameIndexRootPages) Test(org.junit.Test) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamSupport.stream(java.util.stream.StreamSupport.stream) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) MAX_IDX_NAME_LEN(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl.MAX_IDX_NAME_LEN) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) Person(org.apache.ignite.client.Person) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IndexRenameRootPageRecord(org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord) Test(org.junit.Test)

Aggregations

Person (org.apache.ignite.client.Person)21 IgniteEx (org.apache.ignite.internal.IgniteEx)12 Test (org.junit.Test)12 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)7 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)5 HashMap (java.util.HashMap)3 IgniteClient (org.apache.ignite.client.IgniteClient)3 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Index (org.apache.ignite.internal.cache.query.index.Index)2 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 IndexRenameRootPageRecord (org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1