use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class FunctionalQueryTest method testMixedQueryAndCacheApiOperations.
/**
*/
@Test
public void testMixedQueryAndCacheApiOperations() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(new ClientConfiguration().setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)).setAddresses(Config.SERVER))) {
String cacheName = "PersonCache";
client.query(new SqlFieldsQuery(String.format("CREATE TABLE IF NOT EXISTS Person (key INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s,CACHE_NAME=%s\"", Person.class.getName(), cacheName)).setSchema("PUBLIC")).getAll();
client.query(new SqlFieldsQuery("INSERT INTO Person(key, name) VALUES(?, ?)").setArgs(1, "Person 1").setSchema("PUBLIC")).getAll();
ClientCache<Integer, Person> cache = client.cache(cacheName);
cache.put(2, new Person(2, "Person 2"));
assertEquals("Person 1", cache.get(1).getName());
assertEquals("Person 2", client.query(new SqlFieldsQuery("SELECT name FROM PUBLIC.Person WHERE key = 2")).getAll().get(0).get(0));
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SecurityTest method testInvalidUserAuthentication.
/**
* Test valid user authentication.
*/
private void testInvalidUserAuthentication(Consumer<IgniteClient> action) {
Exception authError = null;
try (Ignite ignored = igniteWithAuthentication();
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName("JOE").setUserPassword("password"))) {
action.accept(client);
} catch (Exception e) {
authError = e;
}
assertNotNull("Authentication with invalid credentials succeeded", authError);
assertTrue("Invalid type of authentication error", authError instanceof ClientAuthenticationException);
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SqlViewExporterSpiTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
String host = ignite0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = ignite0.configuration().getLocalHost();
int port = ignite0.configuration().getClientConnectorConfiguration().getPort();
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
List<List<?>> conns = execute(ignite0, "SELECT * FROM SYS.CLIENT_CONNECTIONS");
assertEquals(2, conns.size());
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class WrongQueryEntityFieldTypeTest method withThinClient.
/**
* Perform action with Thin client.
*/
private void withThinClient(BiConsumer<IgniteClient, ClientCache<Integer, Object>> consumer) throws Exception {
startGrids(gridCnt);
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:10800"))) {
ClientCache<Integer, Object> cache = cli.createCache(new ClientCacheConfiguration().setName("TEST").setAtomicityMode(mode).setBackups(backups).setQueryEntities(queryEntity()));
consumer.accept(cli, cache);
assertFalse(sysThreadFail);
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method doTestClientQueryExecutedEvents.
/**
*/
public void doTestClientQueryExecutedEvents(boolean inclSens) throws Exception {
CountDownLatch execLatch = new CountDownLatch(9);
IgnitePredicate<SqlQueryExecutionEvent> lsnr = evt -> {
assertNotNull(evt.text());
if (inclSens)
assertTrue(evt.toString().contains("args="));
else
assertFalse(evt.toString().contains("args="));
execLatch.countDown();
return true;
};
ignite().events().localListen(lsnr, EVT_SQL_QUERY_EXECUTION);
ClientConfiguration cc = new ClientConfiguration().setAddresses(Config.SERVER);
try (IgniteClient client = Ignition.startClient(cc)) {
client.query(new SqlFieldsQuery("create table TEST_TABLE(key int primary key, val int)")).getAll();
client.query(new SqlFieldsQuery("insert into TEST_TABLE values (?, ?)").setArgs(1, 1)).getAll();
client.query(new SqlFieldsQuery("update TEST_TABLE set val = ?2 where key = ?1").setArgs(1, 2)).getAll();
client.query(new SqlFieldsQuery("select * from TEST_TABLE")).getAll();
client.query(new SqlFieldsQuery("create index idx_1 on TEST_TABLE(key)")).getAll();
client.query(new SqlFieldsQuery("drop index idx_1")).getAll();
client.query(new SqlFieldsQuery("alter table TEST_TABLE add column val2 int")).getAll();
client.query(new SqlFieldsQuery("alter table TEST_TABLE drop val2")).getAll();
client.query(new SqlFieldsQuery("drop table TEST_TABLE")).getAll();
assert execLatch.await(3_000, MILLISECONDS);
} finally {
ignite().events().stopLocalListen(lsnr, EVT_SQL_QUERY_EXECUTION);
}
}
Aggregations