@Override public Object call() { Ignition.startClient(getClientConfiguration()); return null; } },
/** * Test client fails on start if server is unavailable */ @Test public void testClientFailsOnStart() { ClientConnectionException expEx = null; try (IgniteClient ignored = Ignition.startClient(getClientConfiguration())) { // No-op. } catch (ClientConnectionException connEx) { expEx = connEx; } catch (Exception ex) { fail(String.format( "%s expected but %s was received: %s", ClientConnectionException.class.getName(), ex.getClass().getName(), ex )); } assertNotNull( String.format("%s expected but no exception was received", ClientConnectionException.class.getName()), expEx ); }
/** * @param cipherSuites list of cipher suites * @param protocols list of protocols * @throws Exception If failed. */ private void checkSuccessfulClientStart(String[] cipherSuites, String[] protocols) throws Exception { this.cipherSuites = F.isEmpty(cipherSuites) ? null : cipherSuites; this.protocols = F.isEmpty(protocols) ? null : protocols; try (IgniteClient client = Ignition.startClient(getClientConfiguration())) { client.getOrCreateCache(TEST_CACHE_NAME); } }
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { ClientCache<Integer, String> cache = client.createCache("testMultithreading");
/** 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"); } }
IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Person, Integer> cache = client.createCache("testBatchPutGet");
/** * 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";
/** 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 testCacheManagement() throws Exception { try (LocalIgniteCluster ignored = LocalIgniteCluster.start(2); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { final String CACHE_NAME = "testCacheManagement";
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); } } }
IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, Person> cache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Person, Integer> cache = client.getOrCreateCache("testPutGet"); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Person, Person> cache = client.getOrCreateCache("testPutGet");
/** * 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); } } }
public void testRemoveReplace() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, String> cache = client.createCache("testRemoveReplace");
/** * Tested API: * <ul> * <li>{@link ClientCache#getAndPut(Object, Object)}</li> * <li>{@link ClientCache#getAndRemove(Object)}</li> * <li>{@link ClientCache#getAndReplace(Object, Object)}</li> * <li>{@link ClientCache#putIfAbsent(Object, Object)}</li> * </ul> */ @Test public void testAtomicPutGet() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, String> cache = client.createCache("testRemoveReplace"); assertNull(cache.getAndPut(1, "1")); assertEquals("1", cache.getAndPut(1, "1.1")); assertEquals("1.1", cache.getAndRemove(1)); assertNull(cache.getAndRemove(1)); assertTrue(cache.putIfAbsent(1, "1")); assertFalse(cache.putIfAbsent(1, "1.1")); assertEquals("1", cache.getAndReplace(1, "1.1")); assertEquals("1.1", cache.getAndReplace(1, "1")); assertNull(cache.getAndReplace(2, "2")); } }