Search in sources :

Example 61 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class PerformanceStatisticsThinClientTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();
    IgniteEx ignite = startGrids(GRIDS_CNT);
    ignite.compute().localDeployTask(TestTask.class, TestTask.class.getClassLoader());
    thinClient = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) TestTask(org.apache.ignite.internal.client.thin.TestTask) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 62 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ClientConfigurationTest method testSerialization.

/**
 * Serialization/deserialization.
 */
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
    ClientConfiguration target = new ClientConfiguration().setAddresses("127.0.0.1:10800", "127.0.0.1:10801").setTimeout(123).setBinaryConfiguration(new BinaryConfiguration().setClassNames(Collections.singleton("Person"))).setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath("client.jks").setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE).setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath("trust.jks").setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE).setSslTrustCertificateKeyStorePassword("123456").setSslKeyAlgorithm(DFLT_KEY_ALGORITHM);
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream(outBytes);
    out.writeObject(target);
    out.flush();
    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(outBytes.toByteArray()));
    Object desTarget = in.readObject();
    assertTrue(Comparers.equal(target, desTarget));
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) ObjectOutput(java.io.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectInput(java.io.ObjectInput) ObjectOutputStream(java.io.ObjectOutputStream) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 63 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ClientListenerMetricsTest method testClientListenerMetricsReject.

/**
 * Check that failed connection attempts to the grid affect metrics.
 */
@Test
public void testClientListenerMetricsReject() throws Exception {
    cleanPersistenceDir();
    IgniteConfiguration nodeCfg = getConfiguration().setClientConnectorConfiguration(new ClientConnectorConfiguration().setHandshakeTimeout(2000)).setAuthenticationEnabled(true).setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true)));
    try (IgniteEx ignite = startGrid(nodeCfg)) {
        ignite.cluster().state(ClusterState.ACTIVE);
        MetricRegistry mreg = ignite.context().metric().registry(CLIENT_CONNECTOR_METRICS);
        checkRejectMetrics(mreg, 0, 0, 0);
        ClientConfiguration cfgSsl = getClientConfiguration().setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath(GridTestUtils.keyStorePath("client")).setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE).setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath(GridTestUtils.keyStorePath("trustone")).setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE).setSslTrustCertificateKeyStorePassword("123456");
        GridTestUtils.assertThrows(log, () -> {
            Ignition.startClient(cfgSsl);
            return null;
        }, ClientException.class, null);
        checkRejectMetrics(mreg, 1, 0, 1);
        ClientConfiguration cfgAuth = getClientConfiguration().setUserName("SomeRandomInvalidName").setUserPassword("42");
        GridTestUtils.assertThrows(log, () -> {
            Ignition.startClient(cfgAuth);
            return null;
        }, ClientAuthenticationException.class, null);
        checkRejectMetrics(mreg, 1, 1, 2);
    }
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 64 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class LoadTest method testMultithreading.

/**
 * Test thin client in multi-thread environment.
 */
@Test
public void testMultithreading() throws Exception {
    final int THREAD_CNT = 8;
    final int ITERATION_CNT = 20;
    final int BATCH_SIZE = 1000;
    final int PAGE_CNT = 3;
    IgniteConfiguration srvCfg = Config.getServerConfiguration();
    // No peer class loading from thin clients: we need the server to know about this class to deserialize
    // ScanQuery filter.
    srvCfg.setBinaryConfiguration(new BinaryConfiguration().setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(getClass().getName()), new BinaryTypeConfiguration(SerializedLambda.class.getName()))));
    try (Ignite ignored = Ignition.start(srvCfg);
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
        ClientCache<Integer, String> cache = client.createCache("testMultithreading");
        AtomicInteger cnt = new AtomicInteger(1);
        AtomicReference<Throwable> error = new AtomicReference<>();
        Runnable assertion = () -> {
            try {
                int rangeStart = cnt.getAndAdd(BATCH_SIZE);
                int rangeEnd = rangeStart + BATCH_SIZE;
                Map<Integer, String> data = IntStream.range(rangeStart, rangeEnd).boxed().collect(Collectors.toMap(i -> i, i -> String.format("String %s", i)));
                cache.putAll(data);
                Query<Cache.Entry<Integer, String>> qry = new ScanQuery<Integer, String>().setPageSize(data.size() / PAGE_CNT).setFilter((i, s) -> i >= rangeStart && i < rangeEnd);
                try (QueryCursor<Cache.Entry<Integer, String>> cur = cache.query(qry)) {
                    List<Cache.Entry<Integer, String>> res = cur.getAll();
                    assertEquals("Unexpected number of entries", data.size(), res.size());
                    Map<Integer, String> act = res.stream().collect(Collectors.toMap(Cache.Entry::getKey, Cache.Entry::getValue));
                    assertEquals("Unexpected entries", data, act);
                }
            } catch (Throwable ex) {
                error.set(ex);
            }
        };
        CountDownLatch complete = new CountDownLatch(THREAD_CNT);
        Runnable manyAssertions = () -> {
            for (int i = 0; i < ITERATION_CNT && error.get() == null; i++) assertion.run();
            complete.countDown();
        };
        ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_CNT);
        IntStream.range(0, THREAD_CNT).forEach(t -> threadPool.submit(manyAssertions));
        assertTrue("Timeout", complete.await(180, TimeUnit.SECONDS));
        String errMsg = error.get() == null ? "" : error.get().getMessage();
        assertNull(errMsg, error.get());
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) AtomicReference(java.util.concurrent.atomic.AtomicReference) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializedLambda(java.lang.invoke.SerializedLambda) Map(java.util.Map) Cache(javax.cache.Cache) Timeout(org.junit.rules.Timeout) ExecutorService(java.util.concurrent.ExecutorService) Query(org.apache.ignite.cache.query.Query) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) Assert.assertNull(org.junit.Assert.assertNull) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Assert.assertEquals(org.junit.Assert.assertEquals) Query(org.apache.ignite.cache.query.Query) ScanQuery(org.apache.ignite.cache.query.ScanQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) QueryCursor(org.apache.ignite.cache.query.QueryCursor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Map(java.util.Map) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 65 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class IgniteBinaryTest method testCompactFooterNestedTypeRegistration.

/**
 * Check that binary types are registered for nested types too.
 * With enabled "CompactFooter" binary type schema also should be passed to server.
 */
@Test
public void testCompactFooterNestedTypeRegistration() throws Exception {
    try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)))) {
            IgniteCache<Integer, Person[]> igniteCache = ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
            ClientCache<Integer, Person[]> clientCache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
            Integer key = 1;
            Person[] val = new Person[] { new Person(1, "Joe") };
            // Binary types should be registered for both "Person[]" and "Person" classes after this call.
            clientCache.put(key, val);
            // Check that we can deserialize on server using registered binary types.
            assertArrayEquals(val, igniteCache.get(key));
        }
    }
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)83 Test (org.junit.Test)44 IgniteClient (org.apache.ignite.client.IgniteClient)42 Ignite (org.apache.ignite.Ignite)28 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)23 BinaryObject (org.apache.ignite.binary.BinaryObject)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 List (java.util.List)11 Ignition (org.apache.ignite.Ignition)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)9 Collections (java.util.Collections)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteBinary (org.apache.ignite.IgniteBinary)7 Connection (java.sql.Connection)6 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Consumer (java.util.function.Consumer)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)6