use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ServicesTest method testWrongServiceName.
/**
* Test that exception is thrown when trying to invoke non-existing service.
*/
@Test
public void testWrongServiceName() throws Exception {
try (IgniteClient client = startClient(0)) {
TestServiceInterface svc = client.services().serviceProxy("no_such_service", TestServiceInterface.class);
GridTestUtils.assertThrowsAnyCause(log, () -> svc.testMethod(0), ClientException.class, "Service not found");
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ServicesTest method testCollectionMethods.
/**
* Test that methods which get and return collections work correctly.
*/
@Test
public void testCollectionMethods() throws Exception {
try (IgniteClient client = startClient(0)) {
// Test local service calls (service deployed to each node).
TestServiceInterface svc = client.services().serviceProxy(NODE_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
checkCollectionMethods(svc);
// Test remote service calls (client connected to grid(0) but service deployed to grid(1)).
svc = client.services().serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
checkCollectionMethods(svc);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ServicesTest method testWrongMethodInvocation.
/**
* Test that exception is thrown when invoking service with wrong interface.
*/
@Test
public void testWrongMethodInvocation() throws Exception {
try (IgniteClient client = startClient(0)) {
TestServiceInterface svc = client.services().serviceProxy(NODE_ID_SERVICE_NAME, TestServiceInterface.class);
GridTestUtils.assertThrowsAnyCause(log, () -> svc.testMethod(0), ClientException.class, "Method not found");
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class IgniteAwareApplicationService method main.
/**
* @param args Args.
*/
public static void main(String[] args) throws Exception {
log.info("Starting Application... [params=" + args[0] + "]");
String[] params = args[0].split(",");
IgniteServiceType svcType = IgniteServiceType.valueOf(params[0]);
Class<?> clazz = Class.forName(params[1]);
String cfgPath = params[2];
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = params.length > 3 ? mapper.readTree(Base64.getDecoder().decode(params[3])) : mapper.createObjectNode();
IgniteAwareApplication app = (IgniteAwareApplication) clazz.getConstructor().newInstance();
app.cfgPath = cfgPath;
if (svcType == IgniteServiceType.NODE) {
log.info("Starting Ignite node...");
IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgs = IgnitionEx.loadConfiguration(cfgPath);
IgniteConfiguration cfg = cfgs.get1();
try (Ignite ignite = Ignition.start(cfg)) {
app.ignite = ignite;
app.start(jsonNode);
} finally {
log.info("Ignite instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
}
} else if (svcType == IgniteServiceType.THIN_CLIENT) {
log.info("Starting thin client...");
ClientConfiguration cfg = IgnitionEx.loadSpringBean(cfgPath, "thin.client.cfg");
try (IgniteClient client = Ignition.startClient(cfg)) {
app.client = client;
app.start(jsonNode);
} finally {
log.info("Thin client instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
}
} else if (svcType == IgniteServiceType.NONE)
app.start(jsonNode);
else
throw new IllegalArgumentException("Unknown service type " + svcType);
}
use of org.apache.ignite.client.IgniteClient 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());
}
}
}
Aggregations