/** */ private static ClientConfiguration getClientConfiguration() { return new ClientConfiguration().setAddresses(Config.SERVER) .setSendBufferSize(0) .setReceiveBufferSize(0); } }
/** */ private static ClientConfiguration getClientConfiguration() { return new ClientConfiguration() .setAddresses(Config.SERVER) .setSendBufferSize(0) .setReceiveBufferSize(0); } }
/** * @return Client config. */ protected ClientConfiguration getClientConfiguration() { ClientConfiguration cfg = new ClientConfiguration(); cfg.setAddresses("127.0.0.1:10800"); cfg.setSslMode(SslMode.REQUIRED); cfg.setSslContextFactory(createSslFactory()); return cfg; }
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { ClientCache<Integer, String> cache = client.createCache("testMultithreading");
/** 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("JKS") .setSslClientCertificateKeyStorePassword("123456") .setSslTrustCertificateKeyStorePath("trust.jks") .setSslTrustCertificateKeyStoreType("JKS") .setSslTrustCertificateKeyStorePassword("123456") .setSslKeyAlgorithm("SunX509"); 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)); }
/** Test valid user authentication. */ @Test public void testValidUserAuthentication() throws Exception { final String USER = "joe"; final String PWD = "password"; try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD)); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER) .setUserName(USER) .setUserPassword(PWD) ) ) { client.getOrCreateCache("testAuthentication"); } }
/** * Create user. */ private static void createUser(String user, String pwd) throws Exception { try (IgniteClient client = Ignition.startClient(new ClientConfiguration() .setAddresses(Config.SERVER) .setUserName("ignite") .setUserPassword("ignite") )) { client.query( new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", user, pwd)) ).getAll(); } } }
public void testBinaryQueries() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { final String TYPE_NAME = "Person";
.setAddresses(cluster.clientAddresses().toArray(new String[CLUSTER_SIZE]))
/** Test user cannot create user. */ @Test public void testUserCannotCreateUser() throws Exception { final String USER = "joe"; final String PWD = "password"; try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD)); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER) .setUserName(USER) .setUserPassword(PWD) ) ) { Exception authError = null; try { client.query( new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", "joe2", "password")) ).getAll(); } catch (Exception e) { authError = e; } assertNotNull("User created another user", authError); } }
public void testBinaryObjectApi() throws Exception { try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
/** * Tested API: * <ul> * <li>{@link IgniteClient#query(SqlFieldsQuery)}</li> * </ul> */ @Test public void testSql() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { client.query( new SqlFieldsQuery(String.format( "CREATE TABLE IF NOT EXISTS Person (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName() )).setSchema("PUBLIC") ).getAll(); int key = 1; Person val = new Person(key, "Person 1"); client.query(new SqlFieldsQuery( "INSERT INTO Person(id, name) VALUES(?, ?)" ).setArgs(val.getId(), val.getName()).setSchema("PUBLIC")) .getAll(); Object cachedName = client.query( new SqlFieldsQuery("SELECT name from Person WHERE id=?").setArgs(key).setSchema("PUBLIC") ).getAll().iterator().next().iterator().next(); assertEquals(val.getName(), cachedName); } }
public void testGettingEmptyResultWhenQueryingEmptyTable() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { final String TBL = "Person";
/** Test valid user authentication. */ @Test public void testInvalidUserAuthentication() { Exception authError = null; try (Ignite ignored = igniteWithAuthentication(); IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER) .setUserName("JOE") .setUserPassword("password") ) ) { client.getOrCreateCache("testAuthentication"); } catch (Exception e) { authError = e; } assertNotNull("Authentication with invalid credentials succeeded", authError); assertTrue("Invalid type of authentication error", authError instanceof ClientAuthenticationException); }
/** * Unmarshalling schema-less Ignite binary objects into Java static types. */ @Test public void testUnmarshalSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME); Person cachedVal = cache.get(key); assertEquals(val, cachedVal); } } }
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses(Config.SERVER);
/** * Reading schema-less Ignite Binary object. */ @Test public void testReadingSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); BinaryObject cachedVal = cache.get(key); assertEquals(val.getId(), cachedVal.field("id")); assertEquals(val.getName(), cachedVal.field("name")); } } }
/** * Put/get operations with Ignite Binary Object API */ @Test public void testBinaryObjectPutGet() throws Exception { int key = 1; try (Ignite ignored = Ignition.start(Config.getServerConfiguration())) { try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { IgniteBinary binary = client.binary(); BinaryObject val = binary.builder("Person") .setField("id", 1, int.class) .setField("name", "Joe", String.class) .build(); ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); cache.put(key, val); BinaryObject cachedVal = client.cache(Config.DEFAULT_CACHE_NAME).<Integer, BinaryObject>withKeepBinary().get(key); assertBinaryObjectsEqual(val, cachedVal); } } }