use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class ReliableChannelTest method checkFailAfterSendOperation.
/**
*/
private void checkFailAfterSendOperation(Consumer<TcpClientCache> op, boolean channelsReinitOnFail) {
ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs);
// Emulate cluster is down after TcpClientChannel#send operation.
AtomicInteger step = new AtomicInteger();
ReliableChannel rc = new ReliableChannel((cfg, hnd) -> {
if (step.getAndIncrement() == 0)
return new TestAsyncServiceFailureClientChannel();
else
return new TestFailureClientChannel();
}, ccfg, null);
rc.channelsInit();
rc.getScheduledChannelsReinit().set(channelsReinitOnFail);
ClientBinaryMarshaller marsh = mock(ClientBinaryMarshaller.class);
TcpClientTransactions transactions = mock(TcpClientTransactions.class);
TcpClientCache cache = new TcpClientCache("", rc, marsh, transactions, null, false, null);
GridTestUtils.assertThrowsWithCause(() -> op.accept(cache), TestChannelException.class);
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class ReliableChannelTest method testAddressesOrder.
/**
* Checks that ReliableChannel provides channels in the same order as in ClientConfiguration.
*/
@Test
public void testAddressesOrder() {
String[] addrs = new String[] { "127.0.0.1:10803", "127.0.0.1:10802", "127.0.0.1:10801", "127.0.0.1:10800" };
ClientConfiguration ccfg = new ClientConfiguration().setAddresses(addrs);
ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
rc.channelsInit();
List<ReliableChannel.ClientChannelHolder> holders = rc.getChannelHolders();
assertEquals(addrs.length, holders.size());
for (int i = 0; i < addrs.length; i++) assertEquals(addrs[i], holders.get(i).getAddress().toString());
}
use of org.apache.ignite.configuration.ClientConfiguration 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.configuration.ClientConfiguration in project ignite by apache.
the class FunctionalQueryTest method testGettingEmptyResultWhenQueryingEmptyTable.
/**
*/
@Test
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";
client.query(new SqlFieldsQuery(String.format("CREATE TABLE IF NOT EXISTS " + TBL + " (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName())).setSchema("PUBLIC")).getAll();
// IgniteClient#query() API
List<List<?>> res = client.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll();
assertNotNull(res);
assertEquals(0, res.size());
// ClientCache#query(SqlFieldsQuery) API
ClientCache<Integer, Person> cache = client.cache("SQL_PUBLIC_" + TBL.toUpperCase());
res = cache.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll();
assertNotNull(res);
assertEquals(0, res.size());
// ClientCache#query(ScanQuery) and ClientCache#query(SqlQuery) API
Collection<Query<Cache.Entry<Integer, Person>>> queries = Arrays.asList(new ScanQuery<>(), new SqlQuery<>(Person.class, "1 = 1"));
for (Query<Cache.Entry<Integer, Person>> qry : queries) {
try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache.query(qry)) {
List<Cache.Entry<Integer, Person>> res2 = cur.getAll();
assertNotNull(res2);
assertEquals(0, res2.size());
}
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class FunctionalQueryTest method testSql.
/**
* Tested API:
* <ul>
* <li>{@link IgniteClient#query(SqlFieldsQuery)}</li>
* </ul>
*/
@Test
public void testSql() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
Ignite ignored2 = 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();
final int KEY_COUNT = 10;
for (int i = 0; i < KEY_COUNT; ++i) {
int key = i;
Person val = new Person(key, "Person " + i);
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(1).setSchema("PUBLIC")).getAll().iterator().next().iterator().next();
assertEquals("Person 1", cachedName);
List<List<?>> rows = client.query(new SqlFieldsQuery("SELECT * from Person WHERE id >= ?").setSchema("PUBLIC").setArgs(0).setPageSize(1)).getAll();
assertEquals(KEY_COUNT, rows.size());
}
}
Aggregations