Search in sources :

Example 6 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class RenameIndexTreeTest method findIndexRoots.

/**
 * Finding index root pages.
 *
 * @param cache Cache.
 * @param treeName Index tree name.
 * @param segments Segment count.
 * @return Mapping: segment number -> index root page.
 * @throws Exception If failed.
 */
private Map<Integer, RootPage> findIndexRoots(IgniteCache<Integer, Person> cache, String treeName, int segments) throws Exception {
    GridCacheContext<Integer, Person> cacheCtx = cacheContext(cache);
    Map<Integer, RootPage> rootPages = new HashMap<>();
    for (int i = 0; i < segments; i++) {
        RootPage rootPage = cacheCtx.offheap().findRootPageForIndex(cacheCtx.cacheId(), treeName, i);
        if (rootPage != null)
            rootPages.put(i, rootPage);
    }
    return rootPages;
}
Also used : HashMap(java.util.HashMap) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) Person(org.apache.ignite.client.Person)

Example 7 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class StopNodeOnRebuildIndexFailureTest method startBuildIndexAndThrowExceptionTest.

/**
 */
private void startBuildIndexAndThrowExceptionTest(Supplier<? extends Throwable> throwableSupplier) throws Exception {
    errorSupplier = throwableSupplier;
    Throwable t = throwableSupplier.get();
    if (t instanceof Exception && !(t instanceof RuntimeException || t instanceof IgniteCheckedException))
        throw new IllegalArgumentException("Invalid throwable class " + t.getClass());
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    assertEquals(1, G.allGrids().size());
    ignite.cache(CACHE_NAME).put(0, new Person(0, "name"));
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> ignite.cache(CACHE_NAME).query(new SqlFieldsQuery(CREATE_INDEX_SQL)).getAll(), CacheException.class, null);
    assertTrue(exceptionWasThrown.get());
    // Node must be stopped by failure handler.
    assertTrue(GridTestUtils.waitForCondition(() -> G.allGrids().isEmpty(), 5_000));
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Person(org.apache.ignite.client.Person) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 8 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class IndexPagesMetricsPageDisplacementTest method testPageDisplacement.

/**
 * Inserts data into the cache as long as it fills enough for some data pages to get dumped to the
 * storage. Since index page metrics should reflect the number of in-memory pages, the metric value is expected to
 * go down.
 */
@Test
public void testPageDisplacement() throws IgniteCheckedException {
    int grpId = grid.cachex(TEST_CACHE_NAME).context().groupId();
    DataRegion dataRegion = grid.context().cache().context().database().dataRegion(null);
    PageMetrics pageMetrics = dataRegion.metrics().cacheGrpPageMetrics(grpId);
    int personId = 0;
    long idxPagesOnDisk;
    long idxPagesInMemory;
    do {
        // insert data into the cache until some index pages get displaced to the storage
        for (int i = 0; i < 100; i++, personId++) cache.put(personId, new Person(personId, "foobar"));
        forceCheckpoint(grid);
        idxPagesOnDisk = getIdxPagesOnDisk(grpId).size();
        idxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
        assertThat(pageMetrics.indexPages().value(), is(idxPagesInMemory));
    } while (idxPagesOnDisk <= idxPagesInMemory);
    // load pages back into memory and check that the metric value has increased
    touchIdxPages(grpId);
    long allIdxPagesInMemory = idxPageCounter.countIdxPagesInMemory(grpId);
    assertThat(allIdxPagesInMemory, greaterThan(idxPagesInMemory));
    assertThat(pageMetrics.indexPages().value(), is(allIdxPagesInMemory));
}
Also used : PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) Person(org.apache.ignite.client.Person) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class JavaThinCompatibilityTest method testCacheApi.

/**
 */
private void testCacheApi() throws Exception {
    X.println(">>>> Testing cache API");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache("testCacheApi");
        cache.put(1, 1);
        assertEquals(1, cache.get(1));
        Person person = new Person(2, "name");
        cache.put(2, person);
        assertEquals(person, cache.get(2));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) BinaryObject(org.apache.ignite.binary.BinaryObject) Person(org.apache.ignite.client.Person) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 10 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class ComputeTaskTest method testExecuteWithCustomUserType.

/**
 * Test that custom user type can be returned by task.
 */
@Test
public void testExecuteWithCustomUserType() throws Exception {
    try (IgniteClient client = startClient(0)) {
        Person val = client.compute().execute(TestTaskCustomType.class.getName(), "person");
        assertEquals("person", val.getName());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Person(org.apache.ignite.client.Person) 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