Search in sources :

Example 66 with ClientConfiguration

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());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryReader(org.apache.ignite.binary.BinaryReader) Arrays(java.util.Arrays) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) CacheInterceptorAdapter(org.apache.ignite.cache.CacheInterceptorAdapter) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Cache(javax.cache.Cache) IgniteBinary(org.apache.ignite.IgniteBinary) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) Collection(java.util.Collection) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) BinaryType(org.apache.ignite.binary.BinaryType) Assert.assertNull(org.junit.Assert.assertNull) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) BinaryWriter(org.apache.ignite.binary.BinaryWriter) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) Collections(java.util.Collections) BinarySerializer(org.apache.ignite.binary.BinarySerializer) Assert.assertEquals(org.junit.Assert.assertEquals) LogListener(org.apache.ignite.testframework.LogListener) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 67 with ClientConfiguration

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"));
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 68 with ClientConfiguration

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);
        }
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 69 with ClientConfiguration

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());
        }
    }
}
Also used : BinaryWriter(org.apache.ignite.binary.BinaryWriter) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryReader(org.apache.ignite.binary.BinaryReader) BinarySerializer(org.apache.ignite.binary.BinarySerializer) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 70 with ClientConfiguration

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());
}
Also used : ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)83 Test (org.junit.Test)44 IgniteClient (org.apache.ignite.client.IgniteClient)42 Ignite (org.apache.ignite.Ignite)28 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)23 BinaryObject (org.apache.ignite.binary.BinaryObject)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 List (java.util.List)11 Ignition (org.apache.ignite.Ignition)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)9 Collections (java.util.Collections)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteBinary (org.apache.ignite.IgniteBinary)7 Connection (java.sql.Connection)6 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Consumer (java.util.function.Consumer)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)6