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));
}
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));
}
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);
}
}
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());
}
}
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));
}
}
}
Aggregations