/** 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)); }
/** */ public static boolean equal(ClientConfiguration a, Object o) { if (!(o instanceof ClientConfiguration)) return false; ClientConfiguration b = (ClientConfiguration)o; return Arrays.equals(a.getAddresses(), b.getAddresses()) && a.isTcpNoDelay() == b.isTcpNoDelay() && a.getTimeout() == b.getTimeout() && a.getSendBufferSize() == b.getSendBufferSize() && a.getReceiveBufferSize() == b.getReceiveBufferSize(); }
/** */ private static ClientConfiguration getClientConfiguration() { return new ClientConfiguration() .setAddresses(Config.SERVER) .setSendBufferSize(0) .setReceiveBufferSize(0); } }
/** * Constructor. */ ClientChannelConfiguration(ClientConfiguration cfg) { this.sslMode = cfg.getSslMode(); this.tcpNoDelay = cfg.isTcpNoDelay(); this.timeout = cfg.getTimeout(); this.sndBufSize = cfg.getSendBufferSize(); this.rcvBufSize = cfg.getReceiveBufferSize(); this.sslClientCertKeyStorePath = cfg.getSslClientCertificateKeyStorePath(); this.sslClientCertKeyStoreType = cfg.getSslClientCertificateKeyStoreType(); this.sslClientCertKeyStorePwd = cfg.getSslClientCertificateKeyStorePassword(); this.sslTrustCertKeyStorePath = cfg.getSslTrustCertificateKeyStorePath(); this.sslTrustCertKeyStoreType = cfg.getSslTrustCertificateKeyStoreType(); this.sslTrustCertKeyStorePwd = cfg.getSslTrustCertificateKeyStorePassword(); this.sslKeyAlgorithm = cfg.getSslKeyAlgorithm(); this.sslProto = cfg.getSslProtocol(); this.sslTrustAll = cfg.isSslTrustAll(); this.sslCtxFactory = cfg.getSslContextFactory(); this.userName = cfg.getUserName(); this.userPwd = cfg.getUserPassword(); }
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses(Config.SERVER); .setSslMode(SslMode.REQUIRED) .setSslClientCertificateKeyStorePath(rsrcPath.apply("/client.jks")) .setSslClientCertificateKeyStoreType("JKS") .setSslClientCertificateKeyStorePassword("123456") .setSslTrustCertificateKeyStorePath(rsrcPath.apply("/trust.jks")) .setSslTrustCertificateKeyStoreType("JKS") .setSslTrustCertificateKeyStorePassword("123456") .setSslKeyAlgorithm("SunX509") .setSslTrustAll(false) .setSslProtocol(SslProtocol.TLS) )) { client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1"); .setSslMode(SslMode.REQUIRED) .setSslContextFactory(sslCfg) )) { client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
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"); } }
/** * @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; }
/** * Constructor. */ ReliableChannel( Function<ClientChannelConfiguration, Result<ClientChannel>> chFactory, ClientConfiguration clientCfg ) throws ClientException { if (chFactory == null) throw new NullPointerException("chFactory"); if (clientCfg == null) throw new NullPointerException("clientCfg"); this.chFactory = chFactory; this.clientCfg = clientCfg; List<InetSocketAddress> addrs = parseAddresses(clientCfg.getAddresses()); primary = addrs.get(new Random().nextInt(addrs.size())); // we already verified there is at least one address ch = chFactory.apply(new ClientChannelConfiguration(clientCfg).setAddress(primary)).get(); for (InetSocketAddress a : addrs) if (a != primary) this.backups.add(a); }
/** * Constructor. */ ClientChannelConfiguration(ClientConfiguration cfg) { this.sslMode = cfg.getSslMode(); this.tcpNoDelay = cfg.isTcpNoDelay(); this.timeout = cfg.getTimeout(); this.sndBufSize = cfg.getSendBufferSize(); this.rcvBufSize = cfg.getReceiveBufferSize(); this.sslClientCertKeyStorePath = cfg.getSslClientCertificateKeyStorePath(); this.sslClientCertKeyStoreType = cfg.getSslClientCertificateKeyStoreType(); this.sslClientCertKeyStorePwd = cfg.getSslClientCertificateKeyStorePassword(); this.sslTrustCertKeyStorePath = cfg.getSslTrustCertificateKeyStorePath(); this.sslTrustCertKeyStoreType = cfg.getSslTrustCertificateKeyStoreType(); this.sslTrustCertKeyStorePwd = cfg.getSslTrustCertificateKeyStorePassword(); this.sslKeyAlgorithm = cfg.getSslKeyAlgorithm(); this.sslProto = cfg.getSslProtocol(); this.sslTrustAll = cfg.isSslTrustAll(); this.sslCtxFactory = cfg.getSslContextFactory(); this.userName = cfg.getUserName(); this.userPwd = cfg.getUserPassword(); }
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";
/** * 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(); } } }
/** * Constructor. */ ReliableChannel( Function<ClientChannelConfiguration, Result<ClientChannel>> chFactory, ClientConfiguration clientCfg ) throws ClientException { if (chFactory == null) throw new NullPointerException("chFactory"); if (clientCfg == null) throw new NullPointerException("clientCfg"); this.chFactory = chFactory; this.clientCfg = clientCfg; List<InetSocketAddress> addrs = parseAddresses(clientCfg.getAddresses()); primary = addrs.get(new Random().nextInt(addrs.size())); // we already verified there is at least one address ch = chFactory.apply(new ClientChannelConfiguration(clientCfg).setAddress(primary)).get(); for (InetSocketAddress a : addrs) if (a != primary) this.backups.add(a); }
IgniteClient client = Ignition.startClient(new ClientConfiguration() .setAddresses(cluster.clientAddresses().toArray(new String[CLUSTER_SIZE]))
/** 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); }
/** */ private static ClientConfiguration getClientConfiguration() { return new ClientConfiguration().setAddresses(Config.SERVER) .setSendBufferSize(0) .setReceiveBufferSize(0); } }
/** * 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); } } }
/** 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); } }
/** * 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";