Search in sources :

Example 26 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ReliableChannelTest method testReinitDuplicatedAddress.

/**
 * Checks that reinitialization of duplicated address is correct.
 */
@Test
public void testReinitDuplicatedAddress() {
    TestAddressFinder finder = new TestAddressFinder().nextAddresesResponse("127.0.0.1:10800", "127.0.0.1:10801", "127.0.0.1:10802").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10805").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10806").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10806").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10803").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10804").nextAddresesResponse("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10804").nextAddresesResponse("127.0.0.1:10800", "127.0.0.1:10801", "127.0.0.1:10802");
    ClientConfiguration ccfg = new ClientConfiguration().setAddressesFinder(finder);
    ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
    Supplier<List<String>> holderAddresses = () -> rc.getChannelHolders().stream().map(h -> h.getAddress().toString()).sorted().collect(Collectors.toList());
    Consumer<List<String>> assertAddrReInitAndEqualsTo = (addrs) -> {
        rc.channelsInit();
        assertEquals(addrs, holderAddresses.get());
    };
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10800", "127.0.0.1:10801", "127.0.0.1:10802"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10805"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10806"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10806"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10803"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10803", "127.0.0.1:10804"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10803", "127.0.0.1:10804", "127.0.0.1:10804"));
    assertAddrReInitAndEqualsTo.accept(Arrays.asList("127.0.0.1:10800", "127.0.0.1:10801", "127.0.0.1:10802"));
}
Also used : Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) ClientException(org.apache.ignite.client.ClientException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) LinkedList(java.util.LinkedList) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) F(org.apache.ignite.internal.util.typedef.F) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClientAddressFinder(org.apache.ignite.client.ClientAddressFinder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ClientConnectionMultiplexer(org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Consumer(java.util.function.Consumer) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Assert.assertFalse(org.junit.Assert.assertFalse) Queue(java.util.Queue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 27 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ReliableChannelTest method testNodeChannelsAreNotCleaned.

/**
 * Checks that node channels are persisted if channels are reinit with static address configuration.
 */
@Test
public void testNodeChannelsAreNotCleaned() {
    ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs).setPartitionAwarenessEnabled(false);
    ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
    rc.channelsInit();
    // Trigger TestClientChannel creation.
    rc.service(null, null, null);
    assertEquals(1, rc.getNodeChannels().size());
    // Imitate topology change.
    rc.initChannelHolders();
    assertEquals(1, rc.getNodeChannels().size());
}
Also used : ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 28 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ReliableChannelTest method testChannelsNotReinitForStaticAddressConfiguration.

/**
 * Checks that channel holders are not reinited for static address configuration.
 */
@Test
public void testChannelsNotReinitForStaticAddressConfiguration() {
    ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs);
    checkDoesNotReinit(ccfg);
}
Also used : ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 29 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ReliableChannelTest method testDynamicAddressReinitializedCorrectly.

/**
 * Checks that channels are changed (add new, remove old) and close channels if reinitialization performed.
 */
@Test
public void testDynamicAddressReinitializedCorrectly() {
    TestAddressFinder finder = new TestAddressFinder().nextAddresesResponse(dfltAddrs).nextAddresesResponse("127.0.0.1:10800", "127.0.0.1:10803");
    ClientConfiguration ccfg = new ClientConfiguration().setAddressesFinder(finder);
    ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
    rc.channelsInit();
    List<ReliableChannel.ClientChannelHolder> originChannels = Collections.unmodifiableList(rc.getChannelHolders());
    // Imitate topology change.
    rc.initChannelHolders();
    assertEquals(2, F.size(originChannels, ReliableChannel.ClientChannelHolder::isClosed));
    List<ReliableChannel.ClientChannelHolder> reuseChannel = originChannels.stream().filter(c -> !c.isClosed()).collect(Collectors.toList());
    assertEquals(1, reuseChannel.size());
    List<ReliableChannel.ClientChannelHolder> newChannels = rc.getChannelHolders();
    assertEquals(2, newChannels.size());
    assertTrue(newChannels.get(0) == reuseChannel.get(0) || newChannels.get(1) == reuseChannel.get(0));
    newChannels.forEach(c -> assertFalse(c.isClosed()));
}
Also used : Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) ClientException(org.apache.ignite.client.ClientException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) LinkedList(java.util.LinkedList) ClientAuthorizationException(org.apache.ignite.client.ClientAuthorizationException) F(org.apache.ignite.internal.util.typedef.F) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClientAddressFinder(org.apache.ignite.client.ClientAddressFinder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ClientConnectionMultiplexer(org.apache.ignite.internal.client.thin.io.ClientConnectionMultiplexer) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Consumer(java.util.function.Consumer) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Assert.assertFalse(org.junit.Assert.assertFalse) Queue(java.util.Queue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) Mockito.mock(org.mockito.Mockito.mock) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 30 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ReliableChannelTest method testFailOnInitIfDefaultChannelFailed.

/**
 * Should fail if default channel is not initialized.
 */
@Test(expected = TestChannelException.class)
public void testFailOnInitIfDefaultChannelFailed() {
    ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs).setPartitionAwarenessEnabled(true);
    ReliableChannel rc = new ReliableChannel((cfg, hnd) -> new TestFailureClientChannel(), ccfg, null);
    rc.channelsInit();
}
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