.setQueryEntities(qryPerson); ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache(cacheCfg).withKeepBinary(); final IgniteBinary binary = client.binary();
Person val = new Person(key, Integer.toString(key)); ClientCache<Integer, Person> cache = client.getOrCreateCache(cacheCfg); assertEquals(2, cache.size(CachePeekMode.ALL)); cache = client.cache(CACHE_NAME); Object[] cacheNames = new TreeSet<>(client.cacheNames()).toArray(); client.destroyCache(CACHE_NAME); cacheNames = client.cacheNames().toArray(); cache = client.createCache(CACHE_NAME); cacheNames = client.cacheNames().toArray(); client.destroyCache(CACHE_NAME); cache = client.createCache(cacheCfg);
final String TBL = "Person"; client.query( new SqlFieldsQuery(String.format( "CREATE TABLE IF NOT EXISTS " + TBL + " (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", List<List<?>> res = client.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll(); ClientCache<Integer, Person> cache = client.cache("SQL_PUBLIC_" + TBL.toUpperCase());
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");
/** * 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); } } }
/** * @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); } }
IgniteBinary binary = client.binary();
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { ClientCache<Integer, String> cache = client.createCache("testMultithreading");
/** * 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(); } } }
IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, Person> cache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
/** * 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); } } }
); ClientCache cache = client.createCache(cacheCfg);
/** * 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); } }
/** 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"); } }
/** * 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")); } } }
IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, String> cache = client.createCache("testRemoveReplace");
/** 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); } }
final Random rnd = new Random(); final ClientCache<Integer, String> cache = client.getOrCreateCache( new ClientCacheConfiguration().setName("testFailover").setCacheMode(CacheMode.REPLICATED) );
/** * 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")); } }