use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class JmhThinClientAbstractBenchmark method setup.
/**
* Setup routine. Child classes must invoke this method first.
*/
@Setup
public void setup() {
System.out.println();
System.out.println("--------------------");
System.out.println("IGNITE BENCHMARK INFO: ");
System.out.println("\tdata nodes: " + intProperty(PROP_DATA_NODES, DFLT_DATA_NODES));
System.out.println("--------------------");
System.out.println();
int nodesCnt = intProperty(PROP_DATA_NODES, DFLT_DATA_NODES);
A.ensure(nodesCnt >= 1, "nodesCnt >= 1");
node = Ignition.start(configuration("node0"));
for (int i = 1; i < nodesCnt; i++) Ignition.start(configuration("node" + i));
String[] addrs = IntStream.range(10800, 10800 + nodesCnt).mapToObj(p -> "127.0.0.1:" + p).toArray(String[]::new);
ClientConfiguration cfg = new ClientConfiguration().setAddresses(addrs).setPartitionAwarenessEnabled(true);
client = Ignition.startClient(cfg);
cache = client.getOrCreateCache(DEFAULT_CACHE_NAME);
System.out.println("Loading test data...");
for (int i = 0; i < CNT; i++) cache.put(i, PAYLOAD);
System.out.println("Test data loaded: " + CNT);
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class JavaThinCompatibilityTest method testTransactions.
/**
*/
private void testTransactions() throws Exception {
X.println(">>>> Testing transactions");
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
ClientCache<Object, Object> cache = client.getOrCreateCache(new ClientCacheConfiguration().setName("testTransactions").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
try (ClientTransaction tx = client.transactions().txStart()) {
cache.put(1, 1);
cache.put(2, 2);
tx.commit();
}
assertEquals(1, cache.get(1));
assertEquals(2, cache.get(2));
}
}
use of org.apache.ignite.configuration.ClientConfiguration 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));
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class WarningOnBigQueryResultsTest method testThinClient.
/**
*/
@Test
public void testThinClient() throws Exception {
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(THIN_CLI_ADDR))) {
assertEquals(KEYS_PER_NODE * 2, cli.query(new SqlFieldsQueryEx("SELECT * FROM TEST0", true).setSchema("TEST0")).getAll().size());
checkStateAfterQuery0("TEST0");
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class ClientSslUtils method getSslContext.
/**
* Gets SSL context for the given client configuration.
*
* @param cfg Configuration.
* @return {@link SSLContext} when SSL is enabled in the configuration; null otherwise.
*/
public static SSLContext getSslContext(ClientConfiguration cfg) {
if (cfg.getSslMode() == SslMode.DISABLED)
return null;
Factory<SSLContext> sslCtxFactory = cfg.getSslContextFactory();
if (sslCtxFactory != null) {
try {
return sslCtxFactory.create();
} catch (Exception e) {
throw new ClientError("SSL Context Factory failed", e);
}
}
BiFunction<String, String, String> or = (val, dflt) -> val == null || val.isEmpty() ? dflt : val;
String keyStore = or.apply(cfg.getSslClientCertificateKeyStorePath(), System.getProperty("javax.net.ssl.keyStore"));
String keyStoreType = or.apply(cfg.getSslClientCertificateKeyStoreType(), or.apply(System.getProperty("javax.net.ssl.keyStoreType"), DFLT_STORE_TYPE));
String keyStorePwd = or.apply(cfg.getSslClientCertificateKeyStorePassword(), System.getProperty("javax.net.ssl.keyStorePassword"));
String trustStore = or.apply(cfg.getSslTrustCertificateKeyStorePath(), System.getProperty("javax.net.ssl.trustStore"));
String trustStoreType = or.apply(cfg.getSslTrustCertificateKeyStoreType(), or.apply(System.getProperty("javax.net.ssl.trustStoreType"), DFLT_STORE_TYPE));
String trustStorePwd = or.apply(cfg.getSslTrustCertificateKeyStorePassword(), System.getProperty("javax.net.ssl.trustStorePassword"));
String algorithm = or.apply(cfg.getSslKeyAlgorithm(), DFLT_KEY_ALGORITHM);
String proto = toString(cfg.getSslProtocol());
if (Stream.of(keyStore, keyStorePwd, keyStoreType, trustStore, trustStorePwd, trustStoreType).allMatch(s -> s == null || s.isEmpty())) {
try {
return SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new ClientError("Default SSL context cryptographic algorithm is not available", e);
}
}
KeyManager[] keyManagers = getKeyManagers(algorithm, keyStore, keyStoreType, keyStorePwd);
TrustManager[] trustManagers = cfg.isSslTrustAll() ? new TrustManager[] { ignoreErrorsTrustMgr } : getTrustManagers(algorithm, trustStore, trustStoreType, trustStorePwd);
try {
SSLContext sslCtx = SSLContext.getInstance(proto);
sslCtx.init(keyManagers, trustManagers, null);
return sslCtx;
} catch (NoSuchAlgorithmException e) {
throw new ClientError("SSL context cryptographic algorithm is not available", e);
} catch (KeyManagementException e) {
throw new ClientError("Failed to create SSL Context", e);
}
}
Aggregations