Search in sources :

Example 1 with IgniteClient

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

the class JavaThinCompatibilityTest method testBinary.

/**
 */
private void testBinary() throws Exception {
    X.println(">>>> Testing binary");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        IgniteBinary binary = client.binary();
        BinaryObject val = binary.builder("Person").setField("id", 1, int.class).setField("name", "Joe", String.class).build();
        ClientCache<Object, BinaryObject> cache = client.getOrCreateCache("testBinary").withKeepBinary();
        cache.put(0, val);
        BinaryObject cachedVal = cache.get(0);
        assertEquals(val, cachedVal);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObject(org.apache.ignite.binary.BinaryObject) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) IgniteBinary(org.apache.ignite.IgniteBinary)

Example 2 with IgniteClient

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

the class JavaThinCompatibilityTest method testServiceDescriptorsThrows.

/**
 */
private void testServiceDescriptorsThrows() {
    X.println(">>>> Testing services descriptors queries throws");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        String errMsg = "Feature " + GET_SERVICE_DESCRIPTORS.name() + " is not supported by the server";
        Throwable err = assertThrowsWithCause(() -> client.services().serviceDescriptors(), ClientFeatureNotSupportedByServerException.class);
        assertEquals(errMsg, err.getMessage());
        err = assertThrowsWithCause(() -> client.services().serviceDescriptor("test_service"), ClientFeatureNotSupportedByServerException.class);
        assertEquals(errMsg, err.getMessage());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException)

Example 3 with IgniteClient

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

the class JavaThinCompatibilityTest method testCacheConfiguration.

/**
 */
private void testCacheConfiguration(boolean checkFieldsPrecessionAndScale, boolean checkExpiryPlc) throws Exception {
    X.println(">>>> Testing cache configuration");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        String cacheName = "testCacheConfiguration";
        ClientCacheConfiguration ccfg = new ClientCacheConfiguration();
        ccfg.setName(cacheName);
        ccfg.setBackups(3);
        ccfg.setGroupName("cache");
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity qryEntity = new QueryEntity(int.class.getName(), "Entity").setTableName("ENTITY").setFields(new LinkedHashMap<>(F.asMap("id", Integer.class.getName(), "rate", Double.class.getName())));
        if (checkFieldsPrecessionAndScale) {
            qryEntity.setFieldsPrecision(F.asMap("rate", 5));
            qryEntity.setFieldsScale(F.asMap("rate", 2));
        }
        ccfg.setQueryEntities(qryEntity);
        if (checkExpiryPlc)
            ccfg.setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30));
        client.createCache(ccfg);
        ClientCacheConfiguration ccfg1 = client.cache(cacheName).getConfiguration();
        assertEquals(ccfg.getName(), ccfg1.getName());
        assertEquals(ccfg.getBackups(), ccfg1.getBackups());
        assertEquals(ccfg.getGroupName(), ccfg1.getGroupName());
        assertEquals(ccfg.getCacheMode(), ccfg1.getCacheMode());
        assertEquals(ccfg.getQueryEntities().length, ccfg1.getQueryEntities().length);
        assertEquals(ccfg.getQueryEntities()[0].getTableName(), ccfg1.getQueryEntities()[0].getTableName());
        assertEquals(ccfg.getQueryEntities()[0].getFields(), ccfg1.getQueryEntities()[0].getFields());
        if (checkFieldsPrecessionAndScale) {
            assertEquals(ccfg.getQueryEntities()[0].getFieldsPrecision(), ccfg1.getQueryEntities()[0].getFieldsPrecision());
            assertEquals(ccfg.getQueryEntities()[0].getFieldsScale(), ccfg1.getQueryEntities()[0].getFieldsScale());
        }
        if (checkExpiryPlc) {
            assertEquals(ccfg.getExpiryPolicy().getExpiryForCreation(), ccfg1.getExpiryPolicy().getExpiryForCreation());
            assertEquals(ccfg.getExpiryPolicy().getExpiryForAccess(), ccfg1.getExpiryPolicy().getExpiryForAccess());
            assertEquals(ccfg.getExpiryPolicy().getExpiryForUpdate(), ccfg1.getExpiryPolicy().getExpiryForUpdate());
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) QueryEntity(org.apache.ignite.cache.QueryEntity) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 4 with IgniteClient

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

the class JavaThinCompatibilityTest method testQueries.

/**
 */
private void testQueries() throws Exception {
    X.println(">>>> Testing queries");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache("testQueries");
        cache.put(1, 1);
        List<Cache.Entry<Object, Object>> res = cache.query(new ScanQuery<>()).getAll();
        assertEquals(1, res.size());
        assertEquals(1, res.get(0).getKey());
        assertEquals(1, res.get(0).getValue());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ScanQuery(org.apache.ignite.cache.query.ScanQuery) BinaryObject(org.apache.ignite.binary.BinaryObject) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 5 with IgniteClient

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

the class JmxExporterSpiTest method testClientsConnections.

/**
 */
@Test
public void testClientsConnections() throws Exception {
    String host = ignite.configuration().getClientConnectorConfiguration().getHost();
    if (host == null)
        host = ignite.configuration().getLocalHost();
    int port = ignite.configuration().getClientConnectorConfiguration().getPort();
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
        try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
            TabularDataSupport conns = systemView(CLI_CONN_VIEW);
            Consumer<CompositeData> checkThin = c -> {
                assertEquals("THIN", c.get("type"));
                assertTrue(c.get("localAddress").toString().endsWith(Integer.toString(port)));
                assertEquals(c.get("version"), ProtocolVersion.LATEST_VER.toString());
            };
            Consumer<CompositeData> checkJdbc = c -> {
                assertEquals("JDBC", c.get("type"));
                assertTrue(c.get("localAddress").toString().endsWith(Integer.toString(port)));
                assertEquals(c.get("version"), JdbcConnectionContext.CURRENT_VER.asString());
            };
            CompositeData c0 = conns.get(new Object[] { 0 });
            CompositeData c1 = conns.get(new Object[] { 1 });
            if (c0.get("type").equals("JDBC")) {
                checkJdbc.accept(c0);
                checkThin.accept(c1);
            } else {
                checkJdbc.accept(c1);
                checkThin.accept(c0);
            }
            assertEquals(2, conns.size());
        }
    }
    boolean res = GridTestUtils.waitForCondition(() -> systemView(CLI_CONN_VIEW).isEmpty(), 5_000);
    assertTrue(res);
}
Also used : Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) Map(java.util.Map) FILTER_OPERATION(org.apache.ignite.internal.managers.systemview.SystemViewMBean.FILTER_OPERATION) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) CACHE_METRICS(org.apache.ignite.internal.processors.cache.CacheMetricsImpl.CACHE_METRICS) GC_CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD_DESCRIPTION) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) MBeanOperationInfo(javax.management.MBeanOperationInfo) Set(java.util.Set) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TEST_TRANSFORMER(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER) MBeanFeatureInfo(javax.management.MBeanFeatureInfo) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) DynamicMBean(javax.management.DynamicMBean) VIEWS(org.apache.ignite.internal.managers.systemview.SystemViewMBean.VIEWS) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CPU_LOAD_DESCRIPTION(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD_DESCRIPTION) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) IgniteClient(org.apache.ignite.client.IgniteClient) TEST_PREDICATE(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE) TestTransformer(org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) CompositeData(javax.management.openmbean.CompositeData) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.CPU_LOAD) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CachePagesListViewWalker(org.apache.ignite.internal.managers.systemview.walker.CachePagesListViewWalker) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) Connection(java.sql.Connection) ProtocolVersion(org.apache.ignite.internal.client.thin.ProtocolVersion) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LocalTime(java.time.LocalTime) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) DateFormat(java.text.DateFormat) Collectors.toSet(java.util.stream.Collectors.toSet) CyclicBarrier(java.util.concurrent.CyclicBarrier) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) IGNITE_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.IGNITE_METRICS) MetricRegistryMBean.searchHistogram(org.apache.ignite.spi.metric.jmx.MetricRegistryMBean.searchHistogram) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) TabularDataSupport(javax.management.openmbean.TabularDataSupport) Optional(java.util.Optional) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) SYS_METRICS(org.apache.ignite.internal.processors.metric.GridMetricManager.SYS_METRICS) DummyService(org.apache.ignite.internal.processors.service.DummyService) Arrays.stream(java.util.Arrays.stream) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) MBeanParameterInfo(javax.management.MBeanParameterInfo) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) TestRunnable(org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable) GC_CPU_LOAD(org.apache.ignite.internal.processors.metric.GridMetricManager.GC_CPU_LOAD) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) TestPredicate(org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate) F(org.apache.ignite.internal.util.typedef.F) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) JdbcConnectionContext(org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Ignition(org.apache.ignite.Ignition) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) Connection(java.sql.Connection) Properties(java.util.Properties) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) 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