Java Code Examples for org.apache.ignite.Ignition#startClient()
The following examples show how to use
org.apache.ignite.Ignition#startClient() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdditionalSecurityCheckTest.java From ignite with Apache License 2.0 | 6 votes |
/** * */ @Test public void testClientInfoIgniteClientFail() throws Exception { Ignite ignite = startGrids(2); assertEquals(2, ignite.cluster().topologyVersion()); startGrid(2); assertEquals(3, ignite.cluster().topologyVersion()); fail = true; try (IgniteClient client = Ignition.startClient(getClientConfiguration())) { fail(); } catch (ClientAuthenticationException e) { assertTrue(e.getMessage().contains("Client version is not found")); } }
Example 2
Source File: SecurityTest.java From ignite with Apache License 2.0 | 6 votes |
/** 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); }
Example 3
Source File: SecurityTest.java From ignite with Apache License 2.0 | 6 votes |
/** 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); } }
Example 4
Source File: AdditionalSecurityCheckTest.java From ignite with Apache License 2.0 | 6 votes |
/** * */ @Test public void testClientInfo() throws Exception { Ignite ignite = startGrids(2); assertEquals(2, ignite.cluster().topologyVersion()); startGrid(2); assertEquals(3, ignite.cluster().topologyVersion()); assertFalse(ignite.cluster().active()); try (GridClient client = GridClientFactory.start(getGridClientConfiguration())) { assertTrue(client.connected()); client.state().state(ACTIVE, false); } try (IgniteClient client = Ignition.startClient(getClientConfiguration())) { client.createCache("test_cache"); assertEquals(1, client.cacheNames().size()); } }
Example 5
Source File: FunctionalTest.java From ignite with Apache License 2.0 | 6 votes |
/** * 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")); } }
Example 6
Source File: ThinClientPermissionCheckTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param userName User name. * @return Thin client for specified user. */ private IgniteClient startClient(String userName) { return Ignition.startClient( new ClientConfiguration().setAddresses(Config.SERVER) .setUserName(userName) .setUserPassword("") .setUserAttributes(userAttributres()) ); }
Example 7
Source File: AbstractThinClientTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Start thin client with configured endpoints to specified nodes. * * @param nodes Nodes to connect. * @return Thin client. */ protected IgniteClient startClient(ClusterNode... nodes) { String[] addrs = new String[nodes.length]; for (int i = 0; i < nodes.length; i++) { ClusterNode node = nodes[i]; addrs[i] = F.first(node.addresses()) + ":" + node.attribute(ClientListenerProcessor.CLIENT_LISTENER_PORT); } return Ignition.startClient(getClientConfiguration().setAddresses(addrs)); }
Example 8
Source File: SecurityTest.java From ignite with Apache License 2.0 | 5 votes |
/** 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"); } }
Example 9
Source File: ReliabilityTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Test that failover doesn't lead to silent query inconsistency. */ @Test public void testQueryConsistencyOnFailover() throws Exception { int CLUSTER_SIZE = 2; try (LocalIgniteCluster cluster = LocalIgniteCluster.start(CLUSTER_SIZE); IgniteClient client = Ignition.startClient(new ClientConfiguration() .setAddresses(cluster.clientAddresses().toArray(new String[CLUSTER_SIZE]))) ) { ClientCache<Integer, Integer> cache = client.createCache("cache"); cache.put(0, 0); cache.put(1, 1); Query<Cache.Entry<Integer, String>> qry = new ScanQuery<Integer, String>().setPageSize(1); try (QueryCursor<Cache.Entry<Integer, String>> cur = cache.query(qry)) { int cnt = 0; for (Iterator<Cache.Entry<Integer, String>> it = cur.iterator(); it.hasNext(); it.next()) { cnt++; if (cnt == 1) { for (int i = 0; i < CLUSTER_SIZE; i++) dropAllThinClientConnections(Ignition.allGrids().get(i)); } } fail("ClientReconnectedException must be thrown"); } catch (ClientReconnectedException expected) { // No-op. } } }
Example 10
Source File: WarningOnBigQueryResultsTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ @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"); } }
Example 11
Source File: IgniteBinaryTest.java From ignite with Apache License 2.0 | 5 votes |
/** * 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); } } }
Example 12
Source File: ConnectionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param addrs Addresses to connect. */ private void testConnection(String... addrs) throws Exception { try (LocalIgniteCluster cluster = LocalIgniteCluster.start(1); IgniteClient client = Ignition.startClient(new ClientConfiguration() .setAddresses(addrs))) { } }
Example 13
Source File: ReliabilityTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Thin clint failover. */ @Test public void testFailover() throws Exception { final int CLUSTER_SIZE = 3; try (LocalIgniteCluster cluster = LocalIgniteCluster.start(CLUSTER_SIZE); IgniteClient client = Ignition.startClient(new ClientConfiguration() .setReconnectThrottlingRetries(0) // Disable throttling. .setAddresses(cluster.clientAddresses().toArray(new String[CLUSTER_SIZE])) ) ) { final Random rnd = new Random(); final ClientCache<Integer, String> cache = client.getOrCreateCache( new ClientCacheConfiguration().setName("testFailover").setCacheMode(CacheMode.REPLICATED) ); // Simple operation failover: put/get assertOnUnstableCluster(cluster, () -> { Integer key = rnd.nextInt(); String val = key.toString(); cache.put(key, val); String cachedVal = cache.get(key); assertEquals(val, cachedVal); }); cache.clear(); // Composite operation failover: query Map<Integer, String> data = IntStream.rangeClosed(1, 1000).boxed() .collect(Collectors.toMap(i -> i, i -> String.format("String %s", i))); assertOnUnstableCluster(cluster, () -> { cache.putAll(data); Query<Cache.Entry<Integer, String>> qry = new ScanQuery<Integer, String>().setPageSize(data.size() / 10); 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); } }); // Client fails if all nodes go down cluster.close(); boolean igniteUnavailable = false; try { cache.put(1, "1"); } catch (ClientConnectionException ex) { igniteUnavailable = true; Throwable[] suppressed = ex.getSuppressed(); assertEquals(suppressed.length, CLUSTER_SIZE - 1); assertTrue(Stream.of(suppressed).allMatch(t -> t instanceof ClientConnectionException)); } assertTrue(igniteUnavailable); } }
Example 14
Source File: FunctionalTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Test cache operations with different data types. */ @Test public void testDataTypes() throws Exception { try (Ignite ignite = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME); Person person = new Person(1, "name"); // Primitive and built-in types. checkDataType(client, ignite, (byte)1); checkDataType(client, ignite, (short)1); checkDataType(client, ignite, 1); checkDataType(client, ignite, 1L); checkDataType(client, ignite, 1.0f); checkDataType(client, ignite, 1.0d); checkDataType(client, ignite, 'c'); checkDataType(client, ignite, true); checkDataType(client, ignite, "string"); checkDataType(client, ignite, UUID.randomUUID()); checkDataType(client, ignite, new Date()); // Enum. checkDataType(client, ignite, CacheAtomicityMode.ATOMIC); // Binary object. checkDataType(client, ignite, person); // Arrays. checkDataType(client, ignite, new byte[] {(byte)1}); checkDataType(client, ignite, new short[] {(short)1}); checkDataType(client, ignite, new int[] {1}); checkDataType(client, ignite, new long[] {1L}); checkDataType(client, ignite, new float[] {1.0f}); checkDataType(client, ignite, new double[] {1.0d}); checkDataType(client, ignite, new char[] {'c'}); checkDataType(client, ignite, new boolean[] {true}); checkDataType(client, ignite, new String[] {"string"}); checkDataType(client, ignite, new UUID[] {UUID.randomUUID()}); checkDataType(client, ignite, new Date[] {new Date()}); checkDataType(client, ignite, new int[][] {new int[] {1}}); checkDataType(client, ignite, new CacheAtomicityMode[] {CacheAtomicityMode.ATOMIC}); checkDataType(client, ignite, new Person[] {person}); checkDataType(client, ignite, new Person[][] {new Person[] {person}}); checkDataType(client, ignite, new Object[] {1, "string", person, new Person[] {person}}); // Lists. checkDataType(client, ignite, Collections.emptyList()); checkDataType(client, ignite, Collections.singletonList(person)); checkDataType(client, ignite, Arrays.asList(person, person)); checkDataType(client, ignite, new ArrayList<>(Arrays.asList(person, person))); checkDataType(client, ignite, new LinkedList<>(Arrays.asList(person, person))); checkDataType(client, ignite, Arrays.asList(Arrays.asList(person, person), person)); // Sets. checkDataType(client, ignite, Collections.emptySet()); checkDataType(client, ignite, Collections.singleton(person)); checkDataType(client, ignite, new HashSet<>(Arrays.asList(1, 2))); checkDataType(client, ignite, new HashSet<>(Arrays.asList(Arrays.asList(person, person), person))); checkDataType(client, ignite, new HashSet<>(new ArrayList<>(Arrays.asList(Arrays.asList(person, person), person)))); // Maps. checkDataType(client, ignite, Collections.emptyMap()); checkDataType(client, ignite, Collections.singletonMap(1, person)); checkDataType(client, ignite, F.asMap(1, person)); checkDataType(client, ignite, new HashMap<>(F.asMap(1, person))); checkDataType(client, ignite, new HashMap<>(F.asMap(new HashSet<>(Arrays.asList(1, 2)), Arrays.asList(person, person)))); } }
Example 15
Source File: FunctionalTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Tested API: * <ul> * <li>{@link ClientCache#getName()}</li> * <li>{@link ClientCache#getConfiguration()}</li> * </ul> */ @Test public void testCacheConfiguration() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { final String CACHE_NAME = "testCacheConfiguration"; ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName(CACHE_NAME) .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) .setBackups(3) .setCacheMode(CacheMode.PARTITIONED) .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) .setEagerTtl(false) .setGroupName("FunctionalTest") .setDefaultLockTimeout(12345) .setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_ALL) .setReadFromBackup(true) .setRebalanceBatchSize(67890) .setRebalanceBatchesPrefetchCount(102938) .setRebalanceDelay(54321) .setRebalanceMode(CacheRebalanceMode.SYNC) .setRebalanceOrder(2) .setRebalanceThrottle(564738) .setRebalanceTimeout(142536) .setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId")) .setQueryEntities(new QueryEntity(int.class.getName(), "Employee") .setTableName("EMPLOYEE") .setFields( Stream.of( new SimpleEntry<>("id", Integer.class.getName()), new SimpleEntry<>("orgId", Integer.class.getName()) ).collect(Collectors.toMap( SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new )) ) // During query normalization null keyFields become empty set. // Set empty collection for comparator. .setKeyFields(Collections.emptySet()) .setKeyFieldName("id") .setNotNullFields(Collections.singleton("id")) .setDefaultFieldValues(Collections.singletonMap("id", 0)) .setIndexes(Collections.singletonList(new QueryIndex("id", true, "IDX_EMPLOYEE_ID"))) .setAliases(Stream.of("id", "orgId").collect(Collectors.toMap(f -> f, String::toUpperCase))) ) .setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30)); ClientCache cache = client.createCache(cacheCfg); assertEquals(CACHE_NAME, cache.getName()); assertTrue(Comparers.equal(cacheCfg, cache.getConfiguration())); } }
Example 16
Source File: FunctionalQueryTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Tested API: * <ul> * <li>{@link ClientCache#query(Query)}</li> * </ul> */ @Test public void testQueries() throws Exception { 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(getClientConfiguration()) ) { ClientCache<Integer, Person> cache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME); Map<Integer, Person> data = IntStream.rangeClosed(1, 100).boxed() .collect(Collectors.toMap(i -> i, i -> new Person(i, String.format("Person %s", i)))); cache.putAll(data); int minId = data.size() / 2 + 1; int pageSize = (data.size() - minId) / 3; int expSize = data.size() - minId + 1; // expected query result size // Expected result Map<Integer, Person> exp = data.entrySet().stream() .filter(e -> e.getKey() >= minId) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); // Scan and SQL queries Collection<Query<Cache.Entry<Integer, Person>>> queries = Arrays.asList( new ScanQuery<Integer, Person>((i, p) -> p.getId() >= minId).setPageSize(pageSize), new SqlQuery<Integer, Person>(Person.class, "id >= ?").setArgs(minId).setPageSize(pageSize) ); for (Query<Cache.Entry<Integer, Person>> qry : queries) { try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache.query(qry)) { List<Cache.Entry<Integer, Person>> res = cur.getAll(); assertEquals( String.format("Unexpected number of rows from %s", qry.getClass().getSimpleName()), expSize, res.size() ); Map<Integer, Person> act = res.stream() .collect(Collectors.toMap(Cache.Entry::getKey, Cache.Entry::getValue)); assertEquals(String.format("unexpected rows from %s", qry.getClass().getSimpleName()), exp, act); } } checkSqlFieldsQuery(cache, minId, pageSize, expSize, exp, true); checkSqlFieldsQuery(cache, minId, pageSize, expSize, exp, false); } }
Example 17
Source File: IgniteBinaryQueryTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Test queries in Ignite binary. */ @Test 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"; QueryEntity qryPerson = new QueryEntity() .setKeyType(Integer.class.getName()) .setValueType(TYPE_NAME) .setFields( Stream.of( new SimpleEntry<>("id", Integer.class.getName()), new SimpleEntry<>("name", String.class.getName()) ).collect(Collectors.toMap( SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new )) ) .setIndexes(Collections.singletonList(new QueryIndex("id"))); ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName("testBinaryQueries") .setQueryEntities(qryPerson); ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache(cacheCfg).withKeepBinary(); final IgniteBinary binary = client.binary(); Map<Integer, BinaryObject> data = IntStream.range(0, 100).boxed().collect(Collectors.toMap( i -> i, i -> binary.builder(TYPE_NAME) .setField("id", i, int.class) .setField("name", String.format("Person %s", i), String.class) .build() )); cache.putAll(data); Cache.Entry<Integer, BinaryObject> p1 = cache .query(new SqlQuery<Integer, BinaryObject>(TYPE_NAME, "id = 1")) .getAll() .iterator() .next(); assertEquals(Integer.valueOf(1), p1.getKey()); assertBinaryObjectsEqual(data.get(1), p1.getValue()); } }
Example 18
Source File: FunctionalQueryTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ @Test 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"; client.query( new SqlFieldsQuery(String.format( "CREATE TABLE IF NOT EXISTS " + TBL + " (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName() )).setSchema("PUBLIC") ).getAll(); // IgniteClient#query() API List<List<?>> res = client.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll(); assertNotNull(res); assertEquals(0, res.size()); // ClientCache#query(SqlFieldsQuery) API ClientCache<Integer, Person> cache = client.cache("SQL_PUBLIC_" + TBL.toUpperCase()); res = cache.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll(); assertNotNull(res); assertEquals(0, res.size()); // ClientCache#query(ScanQuery) and ClientCache#query(SqlQuery) API Collection<Query<Cache.Entry<Integer, Person>>> queries = Arrays.asList( new ScanQuery<>(), new SqlQuery<>(Person.class, "1 = 1") ); for (Query<Cache.Entry<Integer, Person>> qry : queries) { try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache.query(qry)) { List<Cache.Entry<Integer, Person>> res2 = cur.getAll(); assertNotNull(res2); assertEquals(0, res2.size()); } } } }
Example 19
Source File: LoadTest.java From ignite with Apache License 2.0 | 4 votes |
/** * 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()); } }
Example 20
Source File: FunctionalTest.java From ignite with Apache License 2.0 | 2 votes |
/** * Tested API: * <ul> * <li>{@link IgniteClient#cache(String)}</li> * <li>{@link IgniteClient#getOrCreateCache(ClientCacheConfiguration)}</li> * <li>{@link IgniteClient#cacheNames()}</li> * <li>{@link IgniteClient#createCache(String)}</li> * <li>{@link IgniteClient#createCache(ClientCacheConfiguration)}</li> * <li>{@link IgniteCache#size(CachePeekMode...)}</li> * </ul> */ @Test public void testCacheManagement() throws Exception { try (LocalIgniteCluster ignored = LocalIgniteCluster.start(2); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { final String CACHE_NAME = "testCacheManagement"; ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName(CACHE_NAME) .setCacheMode(CacheMode.REPLICATED) .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); int key = 1; Person val = new Person(key, Integer.toString(key)); ClientCache<Integer, Person> cache = client.getOrCreateCache(cacheCfg); cache.put(key, val); assertEquals(1, cache.size()); assertEquals(2, cache.size(CachePeekMode.ALL)); cache = client.cache(CACHE_NAME); Person cachedVal = cache.get(key); assertEquals(val, cachedVal); Object[] cacheNames = new TreeSet<>(client.cacheNames()).toArray(); assertArrayEquals(new TreeSet<>(Arrays.asList(Config.DEFAULT_CACHE_NAME, CACHE_NAME)).toArray(), cacheNames); client.destroyCache(CACHE_NAME); cacheNames = client.cacheNames().toArray(); assertArrayEquals(new Object[] {Config.DEFAULT_CACHE_NAME}, cacheNames); cache = client.createCache(CACHE_NAME); assertFalse(cache.containsKey(key)); cacheNames = client.cacheNames().toArray(); assertArrayEquals(new TreeSet<>(Arrays.asList(Config.DEFAULT_CACHE_NAME, CACHE_NAME)).toArray(), cacheNames); client.destroyCache(CACHE_NAME); cache = client.createCache(cacheCfg); assertFalse(cache.containsKey(key)); assertArrayEquals(new TreeSet<>(Arrays.asList(Config.DEFAULT_CACHE_NAME, CACHE_NAME)).toArray(), cacheNames); } }