Search in sources :

Example 46 with IgniteClient

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

the class JavaThinCompatibilityTest method testServicesWithCallerContext.

/**
 */
private void testServicesWithCallerContext() {
    X.println(">>>> Testing services with caller context");
    ServiceCallContext callCtx = ServiceCallContext.builder().put("key", "value").build();
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        assertEquals("value", client.services().serviceProxy("ctx_service", CtxServiceInterface.class, callCtx).attribute("key"));
    }
}
Also used : ServiceCallContext(org.apache.ignite.services.ServiceCallContext) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 47 with IgniteClient

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

the class JavaThinCompatibilityTest method testServiceDescriptors.

/**
 */
private void testServiceDescriptors() {
    X.println(">>>> Testing services descriptors");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        assertEquals(2, client.services().serviceDescriptors().size());
        ClientServiceDescriptor svc = client.services().serviceDescriptor("test_service");
        assertEquals("test_service", svc.name());
        assertEquals(EchoService.class.getName(), svc.serviceClass());
        assertEquals(0, svc.totalCount());
        assertEquals(1, svc.maxPerNodeCount());
        assertNull(svc.cacheName());
        assertEquals(grid(0).localNode().id(), svc.originNodeId());
        assertEquals(PlatformType.JAVA, svc.platformType());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientServiceDescriptor(org.apache.ignite.client.ClientServiceDescriptor) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 48 with IgniteClient

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

the class JavaThinCompatibilityTest method testContinuousQueries.

/**
 */
private void testContinuousQueries() throws Exception {
    X.println(">>>> Testing continuous queries");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache("testContinuousQueries");
        List<CacheEntryEvent<?, ?>> allEvts = new ArrayList<>();
        cache.query(new ContinuousQuery<>().setLocalListener(evts -> evts.forEach(allEvts::add)));
        cache.put(0, 0);
        cache.put(0, 1);
        cache.remove(0);
        assertTrue(GridTestUtils.waitForCondition(() -> allEvts.size() == 3, 1_000L));
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException) ClientCache(org.apache.ignite.client.ClientCache) ServiceContext(org.apache.ignite.services.ServiceContext) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Cache(javax.cache.Cache) IgniteBinary(org.apache.ignite.IgniteBinary) QueryEntity(org.apache.ignite.cache.QueryEntity) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) Parameterized(org.junit.runners.Parameterized) SERVICE_INVOKE_CALLCTX(org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.SERVICE_INVOKE_CALLCTX) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) GET_SERVICE_DESCRIPTORS(org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature.GET_SERVICE_DESCRIPTORS) IgniteException(org.apache.ignite.IgniteException) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Person(org.apache.ignite.client.Person) ComputeJob(org.apache.ignite.compute.ComputeJob) ComputeTaskAdapter(org.apache.ignite.compute.ComputeTaskAdapter) RunWith(org.junit.runner.RunWith) PlatformType(org.apache.ignite.platform.PlatformType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) ClientTransaction(org.apache.ignite.client.ClientTransaction) IgniteClient(org.apache.ignite.client.IgniteClient) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) Assume(org.junit.Assume) Duration(javax.cache.expiry.Duration) F(org.apache.ignite.internal.util.typedef.F) ServiceCallContext(org.apache.ignite.services.ServiceCallContext) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) Ignite(org.apache.ignite.Ignite) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) ClientServiceDescriptor(org.apache.ignite.client.ClientServiceDescriptor) TimeUnit(java.util.concurrent.TimeUnit) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Ignition(org.apache.ignite.Ignition) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ServiceContextResource(org.apache.ignite.resources.ServiceContextResource) Service(org.apache.ignite.services.Service) CacheMode(org.apache.ignite.cache.CacheMode) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) ArrayList(java.util.ArrayList) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 49 with IgniteClient

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

the class ThinClientPermissionCheckTest method testCacheEntryExpiration.

/**
 * Tests that the expiration of a cache entry does not require any special permissions from the user who adds the
 * entry.
 */
@Test
public void testCacheEntryExpiration() throws Exception {
    CountDownLatch cacheObjExpiredLatch = new CountDownLatch(G.allGrids().size());
    for (Ignite ignite : G.allGrids()) {
        ignite.events().localListen(evt -> {
            if ((evt.type() == EVT_CACHE_OBJECT_EXPIRED && EXPIRATION_TEST_CACHE.equals(((CacheEvent) evt).cacheName())))
                cacheObjExpiredLatch.countDown();
            return true;
        }, EVT_CACHE_OBJECT_EXPIRED);
    }
    try (IgniteClient client = startClient(CLIENT_PUT)) {
        ClientCache<Object, Object> cache = client.cache(EXPIRATION_TEST_CACHE);
        cache.put("key", "val");
        cacheObjExpiredLatch.await(getTestTimeout(), TimeUnit.MILLISECONDS);
        for (Ignite ignite : G.allGrids()) assertNull(ignite.cache(EXPIRATION_TEST_CACHE).get("key"));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) TestObject(org.apache.ignite.internal.processors.cache.eviction.paged.TestObject) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractSecurityTest(org.apache.ignite.internal.processors.security.AbstractSecurityTest) Test(org.junit.Test)

Example 50 with IgniteClient

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

the class ThinClientPermissionCheckTest method testAllowedOperationAfterSecurityViolation.

/**
 */
@Test
public void testAllowedOperationAfterSecurityViolation() throws Exception {
    try (IgniteClient client = startClient(CLIENT_READ)) {
        assertThrowsWithCause(() -> client.cache(CACHE).put("key", "value"), ClientAuthorizationException.class);
        assertNull(client.cache(CACHE).get("key"));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) AbstractSecurityTest(org.apache.ignite.internal.processors.security.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9