Search in sources :

Example 1 with InvalidKeyspaceException

use of com.datastax.oss.driver.api.core.InvalidKeyspaceException in project java-driver by datastax.

the class ChannelPoolInitTest method should_indicate_when_keyspace_failed_on_all_channels.

@Test
public void should_indicate_when_keyspace_failed_on_all_channels() {
    when(defaultProfile.getInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
    MockChannelFactoryHelper factoryHelper = MockChannelFactoryHelper.builder(channelFactory).failure(node, new InvalidKeyspaceException("invalid keyspace")).failure(node, new InvalidKeyspaceException("invalid keyspace")).failure(node, new InvalidKeyspaceException("invalid keyspace")).build();
    CompletionStage<ChannelPool> poolFuture = ChannelPool.init(node, null, NodeDistance.LOCAL, context, "test");
    factoryHelper.waitForCalls(node, 3);
    assertThatStage(poolFuture).isSuccess(pool -> {
        assertThat(pool.isInvalidKeyspace()).isTrue();
        verify(nodeMetricUpdater, VERIFY_TIMEOUT.times(3)).incrementCounter(DefaultNodeMetric.CONNECTION_INIT_ERRORS, null);
    });
}
Also used : InvalidKeyspaceException(com.datastax.oss.driver.api.core.InvalidKeyspaceException) MockChannelFactoryHelper(com.datastax.oss.driver.internal.core.channel.MockChannelFactoryHelper) Test(org.junit.Test)

Example 2 with InvalidKeyspaceException

use of com.datastax.oss.driver.api.core.InvalidKeyspaceException in project java-driver by datastax.

the class SessionLeakIT method should_never_warn_when_session_init_fails.

@Test
public void should_never_warn_when_session_init_fails() {
    SIMULACRON_RULE.cluster().prime(PrimeDsl.when("USE \"non_existent_keyspace\"").then(PrimeDsl.invalid("irrelevant")));
    int threshold = 4;
    // Set the config option explicitly, in case it gets overridden in the test application.conf:
    DriverConfigLoader configLoader = DriverConfigLoader.programmaticBuilder().withInt(DefaultDriverOption.SESSION_LEAK_THRESHOLD, threshold).build();
    // Go over the threshold, no warnings expected
    for (int i = 0; i < threshold + 1; i++) {
        try (Session session = SessionUtils.newSession(SIMULACRON_RULE, CqlIdentifier.fromCql("non_existent_keyspace"), configLoader)) {
            fail("Session %s should have failed to initialize", session.getName());
        } catch (InvalidKeyspaceException e) {
            assertThat(e.getMessage()).isEqualTo("Invalid keyspace non_existent_keyspace");
        }
    }
    verify(appender, never()).doAppend(any());
}
Also used : InvalidKeyspaceException(com.datastax.oss.driver.api.core.InvalidKeyspaceException) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test)

Aggregations

InvalidKeyspaceException (com.datastax.oss.driver.api.core.InvalidKeyspaceException)2 Test (org.junit.Test)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 Session (com.datastax.oss.driver.api.core.session.Session)1 MockChannelFactoryHelper (com.datastax.oss.driver.internal.core.channel.MockChannelFactoryHelper)1 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)1