use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinaryWithNotGenericInterceptor.
/**
* Tests that {@code org.apache.ignite.cache.CacheInterceptor#onBeforePut(javax.cache.Cache.Entry, java.lang.Object)}
* throws correct exception in case while cache operations are called from thin client. Only BinaryObject`s are
* acceptable in this case.
*/
@Test
public void testBinaryWithNotGenericInterceptor() throws Exception {
IgniteConfiguration ccfg = Config.getServerConfiguration().setCacheConfiguration(new CacheConfiguration("test").setInterceptor(new ThinBinaryValueInterceptor()));
String castErr = "cannot be cast to";
String treeErr = "B+Tree is corrupted";
ListeningTestLogger srvLog = new ListeningTestLogger(log);
LogListener lsnrCast = LogListener.matches(castErr).andMatches(str -> !str.contains(treeErr)).build();
srvLog.registerListener(lsnrCast);
ccfg.setGridLogger(srvLog);
try (Ignite ign = Ignition.start(ccfg)) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, ThinBinaryValue> cache = client.cache("test");
try {
cache.put(1, new ThinBinaryValue());
fail();
} catch (Exception e) {
assertFalse(X.getFullStackTrace(e).contains(castErr));
}
ClientProcessorMXBean serverMxBean = getMxBean(ign.name(), "Clients", ClientListenerProcessor.class, ClientProcessorMXBean.class);
serverMxBean.showFullStackOnClientSide(true);
try {
cache.put(1, new ThinBinaryValue());
} catch (Exception e) {
assertTrue(X.getFullStackTrace(e).contains(castErr));
}
}
}
assertTrue(lsnrCast.check());
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testReadingSchemalessIgniteBinaries.
/**
* Reading schema-less Ignite Binary object.
*/
@Test
public void testReadingSchemalessIgniteBinaries() throws Exception {
int key = 1;
Person val = new Person(key, "Joe");
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
// Add an entry directly to the Ignite server. This stores a schema-less object in the cache and
// does not register schema in the client's metadata cache.
srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val);
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
BinaryObject cachedVal = cache.get(key);
assertEquals(val.getId(), cachedVal.field("id"));
assertEquals(val.getName(), cachedVal.field("name"));
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testUnmarshalSchemalessIgniteBinaries.
/**
* Unmarshalling schema-less Ignite binary objects into Java static types.
*/
@Test
public void testUnmarshalSchemalessIgniteBinaries() throws Exception {
int key = 1;
Person val = new Person(key, "Joe");
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
// Add an entry directly to the Ignite server. This stores a schema-less object in the cache and
// does not register schema in the client's metadata cache.
srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val);
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME);
Person cachedVal = cache.get(key);
assertEquals(val, cachedVal);
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryTest method testBinarySerializer.
/**
* Test custom binary type serializer.
*/
@Test
public void testBinarySerializer() throws Exception {
BinarySerializer binSer = new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("f1", ((Person) obj).getId());
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
((Person) obj).setId(reader.readInt("f1"));
}
};
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(Person.class.getName()).setSerializer(binSer);
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.getId(), clientCache.get(1).getId());
assertNull(clientCache.get(1).getName());
assertEquals(val.getId(), igniteCache.get(1).getId());
assertNull(igniteCache.get(1).getName());
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class ReliableChannelTest method testDuplicatedAddressesAreValid.
/**
* Checks that it is possible configure addresses with duplication (for load balancing).
*/
@Test
public void testDuplicatedAddressesAreValid() {
ClientConfiguration ccfg = new ClientConfiguration().setAddresses("127.0.0.1:10800", "127.0.0.1:10800", "127.0.0.1:10801");
ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
rc.channelsInit();
assertEquals(3, rc.getChannelHolders().size());
}
Aggregations