/** * @return String representation of {@link SslProtocol} as required by {@link SSLContext}. */ private static String toString(SslProtocol proto) { switch (proto) { case TLSv1_1: return "TLSv1.1"; case TLSv1_2: return "TLSv1.2"; default: return proto.toString(); } }
/** Read bytes from the input stream. */ private byte[] read(int len) throws ClientConnectionException { byte[] bytes = new byte[len]; int bytesNum; int readBytesNum = 0; while (readBytesNum < len) { try { bytesNum = in.read(bytes, readBytesNum, len - readBytesNum); } catch (IOException e) { throw new ClientConnectionException(e); } if (bytesNum < 0) throw new ClientConnectionException(); readBytesNum += bytesNum; } return bytes; }
/** * Create and start start the cluster. */ public static LocalIgniteCluster start(int initSize) { return new LocalIgniteCluster(initSize); }
/** * 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")); } }
/** * 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); } } }
/** * @throws Exception If failed. */ @Test public void testSameProtocols() throws Exception { protocols = new String[] { "TLSv1.1", "TLSv1.2" }; startGrid(); checkSuccessfulClientStart(null, new String[] { "TLSv1.1", "TLSv1.2" } ); }
/** * @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); } }
/** 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"); } }
/** * @throws Exception If failed. */ @Test public void testNoCommonCipherSuite() throws Exception { cipherSuites = new String[] { "TLS_RSA_WITH_AES_128_GCM_SHA256" }; startGrid(); checkClientStartFailure( new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" }, null ); }
/** @throws IllegalArgumentException if the specified cache name is invalid. */ private static void ensureCacheConfiguration(ClientCacheConfiguration cfg) { if (cfg == null) throw new IllegalArgumentException("Cache configuration must be specified"); ensureCacheName(cfg.getName()); }
/** Private constructor: use {@link #start(int)} to create instances of {@link LocalIgniteCluster}. */ private LocalIgniteCluster(int initSize) { if (initSize < 1) throw new IllegalArgumentException("Cluster must have at least one node."); this.initSize = initSize; for (int i = 0; i < initSize; i++) { IgniteConfiguration cfg = getConfiguration( new NodeConfiguration(TcpDiscoverySpi.DFLT_PORT + i, ClientConnectorConfiguration.DFLT_PORT + i) ); Ignite ignite = Ignition.start(cfg); srvs.add(ignite); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { stopAllGrids(); protocols = null; cipherSuites = null; }
/** * @param cipherSuites list of cipher suites * @param protocols list of protocols */ private void checkClientStartFailure(String[] cipherSuites, String[] protocols) { checkClientStartFailure( cipherSuites, protocols, ClientConnectionException.class, "Ignite cluster is unavailable" ); }
private Iterator<T> nextPage() { try { currPageIt = pager.next().iterator(); return currPageIt; } catch (ClientException e) { throw e; } catch (Exception e) { throw new ClientException("Failed to retrieve query results", e); } } };
@Override public Object call() { Ignition.startClient(getClientConfiguration()); return null; } },
/** * @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; }
/** * @throws Exception If failed. */ @Test public void testOneCommonCipherSuite() throws Exception { cipherSuites = new String[] { "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" }; startGrid(); checkSuccessfulClientStart( new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" }, null ); }
/** * @throws Exception If failed. */ @Test public void testNoCommonProtocols() throws Exception { protocols = new String[] { "TLSv1.1", "SSLv3" }; startGrid(); checkClientStartFailure( null, new String[] { "TLSv1", "TLSv1.2" } ); }
/** Write bytes to the output stream. */ private void write(byte[] bytes, int len) throws ClientConnectionException { try { out.write(bytes, 0, len); out.flush(); } catch (IOException e) { throw new ClientConnectionException(e); } }
/** * @throws Exception If failed. */ @Test public void testOneCommonProtocol() throws Exception { protocols = new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" }; startGrid(); checkSuccessfulClientStart(null, new String[] { "TLSv1.1", "SSLv3" } ); }