Search in sources :

Example 1 with Person

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));
    }
}
Also used : ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) Person(org.apache.ignite.client.Person) Test(org.junit.Test)

Example 2 with Person

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

Example 3 with Person

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;
}
Also used : RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) ArrayList(java.util.ArrayList) Person(org.apache.ignite.client.Person)

Example 4 with Person

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);
}
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 5 with Person

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