use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testCompactFooterModifiedSchemaRegistration.
/**
* Check that binary type schema updates are propagated from client to server and from server to client.
*/
@Test
public void testCompactFooterModifiedSchemaRegistration() throws Exception {
try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true));
try (IgniteClient client1 = Ignition.startClient(cfg);
IgniteClient client2 = Ignition.startClient(cfg)) {
ClientCache<Integer, Object> cache1 = client1.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
ClientCache<Integer, Object> cache2 = client2.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
String type = "Person";
// Register type and schema.
BinaryObjectBuilder builder = client1.binary().builder(type);
BinaryObject val1 = builder.setField("Name", "Person 1").build();
cache1.put(1, val1);
assertEquals("Person 1", ((BinaryObject) cache2.get(1)).field("Name"));
// Update schema.
BinaryObject val2 = builder.setField("Name", "Person 2").setField("Age", 2).build();
cache1.put(2, val2);
assertEquals("Person 2", ((BinaryObject) cache2.get(2)).field("Name"));
assertEquals((Integer) 2, ((BinaryObject) cache2.get(2)).field("Age"));
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinaryObjectPutGet.
/**
* 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);
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SystemViewSelfTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
try (IgniteEx g0 = startGrid(0)) {
String host = g0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = g0.configuration().getLocalHost();
int port = g0.configuration().getClientConnectorConfiguration().getPort();
SystemView<ClientConnectionView> conns = g0.context().systemView().view(CLI_CONN_VIEW);
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
assertEquals(1, conns.size());
ClientConnectionView cliConn = conns.iterator().next();
assertEquals("THIN", cliConn.type());
assertEquals(cliConn.localAddress().getHostName(), cliConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), cliConn.localAddress().getPort());
assertEquals(cliConn.version(), ProtocolVersion.LATEST_VER.toString());
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
assertEquals(2, conns.size());
assertEquals(1, F.size(jdbcConnectionsIterator(conns)));
ClientConnectionView jdbcConn = jdbcConnectionsIterator(conns).next();
assertEquals("JDBC", jdbcConn.type());
assertEquals(jdbcConn.localAddress().getHostName(), jdbcConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), jdbcConn.localAddress().getPort());
assertEquals(jdbcConn.version(), JdbcConnectionContext.CURRENT_VER.asString());
}
}
boolean res = GridTestUtils.waitForCondition(() -> conns.size() == 0, 5_000);
assertTrue(res);
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class ComputeTaskRemoteSecurityContextTest method testIgniteClient.
/**
* Tests task execution security context in case task was initiated from the {@link IgniteClient}.
*/
@Test
public void testIgniteClient() throws Exception {
String login = "thin_client";
ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(login).setUserPassword("");
try (IgniteClient cli = Ignition.startClient(cfg)) {
ClientCompute comp = cli.compute(cli.cluster().forNodes(cli.cluster().nodes()));
if (failWithTimeout)
comp = comp.withTimeout(TEST_TASK_TIMEOUT);
String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
Throwable timeoutE = null;
try {
if (async)
comp.executeAsync2(taskName, login).get();
else
comp.execute(taskName, login);
checkTaskEvents("crd", login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
} catch (Throwable e) {
if (!failWithTimeout)
throw e;
timeoutE = e;
}
if (failWithTimeout) {
assertNotNull(timeoutE);
assertTrue(X.hasCause(timeoutE, "Task timed out", ClientServerError.class));
checkTaskEvents("crd", login, REDUCER_FAILED_TASK_EVENTS, MAP_NODE_FAILED_TASK_EVENTS);
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class OptimizedMarshallerClassesCachedTest method testLocalDateTimeMetaCached.
/**
* Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client.
*/
@Test
public void testLocalDateTimeMetaCached() throws Exception {
try (Ignite srv = startGrid(0)) {
srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());
IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {
@Override
public <T> T service(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.service(op, payloadWriter, payloadReader);
}
@Override
public <T> CompletableFuture<T> serviceAsync(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) {
if (op == ClientOperation.GET_BINARY_TYPE_NAME)
cnt.incrementAndGet();
return super.serviceAsync(op, payloadWriter, payloadReader);
}
}, new ClientConfiguration().setAddresses(Config.SERVER));
try {
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
} finally {
cli.close();
}
assertEquals(1, cnt.get());
}
}
Aggregations