use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SystemViewCommandTest 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 ignored1 = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port));
Connection ignored2 = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
assertEquals(2, systemView(ignite0, CLI_CONN_VIEW).size());
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class CacheEventSecurityContextTest method testIgniteClient.
/**
* Tests cache event security context in case operation is initiated from the {@link IgniteClient}.
*/
@Test
public void testIgniteClient() throws Exception {
operationInitiatorLogin = "thin_client";
ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(operationInitiatorLogin).setUserPassword("");
try (IgniteClient cli = Ignition.startClient(cfg)) {
ClientCache<Integer, String> cache = cli.cache(cacheName);
checkEvents(cli, k -> cache.put(k, "val"), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.putAsync(k, "val").get(), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.putAll(singletonMap(k, "val")), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.putAllAsync(singletonMap(k, "val")).get(), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, cache::remove, true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.removeAsync(k).get(), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.remove(k, "val"), true, EVT_CACHE_OBJECT_REMOVED);
// TODO Add test case inside transaction after resolving IGNITE-14317.
checkEvents(k -> cache.removeAsync(k, "val").get(), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.removeAll(of(k)), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.removeAllAsync(of(k)).get(), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.removeAll(), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.removeAllAsync().get(), true, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.putIfAbsent(k, "val"), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.putIfAbsentAsync(k, "val").get(), false, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.getAndPut(k, "val"), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.getAndPutAsync(k, "val").get(), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, cache::get, true, EVT_CACHE_OBJECT_READ);
checkEvents(cli, k -> cache.getAsync(k).get(), true, EVT_CACHE_OBJECT_READ);
checkEvents(cli, k -> cache.getAll(of(k)), true, EVT_CACHE_OBJECT_READ);
checkEvents(cli, k -> cache.getAllAsync(of(k)).get(), true, EVT_CACHE_OBJECT_READ);
checkEvents(cli, k -> cache.getAndReplace(k, "val"), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.getAndReplaceAsync(k, "val").get(), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, cache::getAndRemove, true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.getAndRemoveAsync(k).get(), true, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
checkEvents(cli, k -> cache.replace(k, "new_val"), true, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.replaceAsync(k, "new_val").get(), true, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.replace(k, "val", "new_val"), true, EVT_CACHE_OBJECT_PUT);
checkEvents(cli, k -> cache.replaceAsync(k, "val", "new_val").get(), true, EVT_CACHE_OBJECT_PUT);
checkEvents(() -> cache.query(new ScanQuery<>()).getAll(), asList(EVT_CACHE_QUERY_EXECUTED, EVT_CACHE_QUERY_OBJECT_READ));
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinaryIdMapper.
/**
* Test custom binary type ID mapper.
*/
@Test
public void testBinaryIdMapper() throws Exception {
BinaryIdMapper idMapper = new BinaryIdMapper() {
@Override
public int typeId(String typeName) {
return typeName.hashCode() % 1000 + 1000;
}
@Override
public int fieldId(int typeId, String fieldName) {
return fieldName.hashCode();
}
};
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(Person.class.getName()).setIdMapper(idMapper);
BinaryConfiguration binCfg = new BinaryConfiguration().setTypeConfigurations(Collections.singleton(typeCfg));
try (Ignite ignite = Ignition.start(Config.getServerConfiguration().setBinaryConfiguration(binCfg))) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setBinaryConfiguration(binCfg))) {
IgniteCache<Integer, Person> igniteCache = ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
ClientCache<Integer, Person> clientCache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
Person val = new Person(123, "Joe");
clientCache.put(1, val);
assertEquals(val, clientCache.get(1));
assertEquals(val, igniteCache.get(1));
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinaryObjectApi.
/**
* Binary Object API:
* {@link IgniteBinary#typeId(String)}
* {@link IgniteBinary#toBinary(Object)}
* {@link IgniteBinary#type(int)}
* {@link IgniteBinary#type(Class)}
* {@link IgniteBinary#type(String)}
* {@link IgniteBinary#types()}
* {@link IgniteBinary#buildEnum(String, int)}
* {@link IgniteBinary#buildEnum(String, String)}
* {@link IgniteBinary#registerEnum(String, Map)}
*/
@Test
public void testBinaryObjectApi() throws Exception {
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
// Use "server-side" IgniteBinary as a reference to test the thin client IgniteBinary against
IgniteBinary refBinary = srv.binary();
IgniteBinary binary = client.binary();
Person obj = new Person(1, "Joe");
int refTypeId = refBinary.typeId(Person.class.getName());
int typeId = binary.typeId(Person.class.getName());
assertEquals(refTypeId, typeId);
BinaryObject refBinObj = refBinary.toBinary(obj);
BinaryObject binObj = binary.toBinary(obj);
assertBinaryObjectsEqual(refBinObj, binObj);
assertBinaryTypesEqual(refBinary.type(typeId), binary.type(typeId));
assertBinaryTypesEqual(refBinary.type(Person.class), binary.type(Person.class));
assertBinaryTypesEqual(refBinary.type(Person.class.getName()), binary.type(Person.class.getName()));
Collection<BinaryType> refTypes = refBinary.types();
Collection<BinaryType> types = binary.types();
assertEquals(refTypes.size(), types.size());
BinaryObject refEnm = refBinary.buildEnum(Enum.class.getName(), Enum.DEFAULT.ordinal());
BinaryObject enm = binary.buildEnum(Enum.class.getName(), Enum.DEFAULT.ordinal());
assertBinaryObjectsEqual(refEnm, enm);
Map<String, Integer> enumMap = Arrays.stream(Enum.values()).collect(Collectors.toMap(java.lang.Enum::name, java.lang.Enum::ordinal));
BinaryType refEnumType = refBinary.registerEnum(Enum.class.getName(), enumMap);
BinaryType enumType = binary.registerEnum(Enum.class.getName(), enumMap);
assertBinaryTypesEqual(refEnumType, enumType);
refEnm = refBinary.buildEnum(Enum.class.getName(), Enum.DEFAULT.name());
enm = binary.buildEnum(Enum.class.getName(), Enum.DEFAULT.name());
assertBinaryObjectsEqual(refEnm, enm);
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinaryTypeWithIdOfMarshallerHeader.
/**
* The purpose of this test is to check that message which begins with the same byte as marshaller header can
* be correctly unmarshalled.
*/
@Test
public void testBinaryTypeWithIdOfMarshallerHeader() throws Exception {
try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
int typeId = GridBinaryMarshaller.OBJ;
BinaryObjectImpl binObj = (BinaryObjectImpl) ignite.binary().builder(Character.toString((char) typeId)).setField("dummy", "dummy").build();
assertEquals(typeId, binObj.typeId());
BinaryType type = client.binary().type(typeId);
assertEquals(binObj.type().typeName(), type.typeName());
}
}
}
Aggregations