Search in sources :

Example 16 with ClientConfiguration

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());
    }
}
Also used : IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) Connection(java.sql.Connection) Properties(java.util.Properties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 17 with ClientConfiguration

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));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) Test(org.junit.Test)

Example 18 with ClientConfiguration

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

Example 19 with ClientConfiguration

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);
        }
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) IgniteBinary(org.apache.ignite.IgniteBinary) 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 20 with ClientConfiguration

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