Search in sources :

Example 1 with SerializableRunnable

use of org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable in project cassandra by apache.

the class InterceptingExecutorFactory method factory.

<F extends ThreadFactory> F factory(String name, Object extraInfo, ThreadGroup threadGroup, UncaughtExceptionHandler uncaughtExceptionHandler, InterceptibleThreadFactory.MetaFactory<F> factory) {
    if (uncaughtExceptionHandler == null)
        uncaughtExceptionHandler = transferToInstance.apply((SerializableFunction<Supplier<Boolean>, UncaughtExceptionHandler>) (reportUnchecked) -> (thread, throwable) -> {
            if (!(throwable instanceof UncheckedInterruptedException) || reportUnchecked.get())
                JVMStabilityInspector.uncaughtException(thread, throwable);
        }).apply(() -> !isClosed);
    if (threadGroup == null)
        threadGroup = this.threadGroup;
    else if (!this.threadGroup.parentOf(threadGroup))
        throw new IllegalArgumentException();
    Runnable onTermination = transferToInstance.apply((SerializableRunnable) FastThreadLocal::removeAll);
    LocalTime time = transferToInstance.apply((IIsolatedExecutor.SerializableCallable<LocalTime>) SimulatedTime.Global::current).call();
    return factory.create(name, Thread.NORM_PRIORITY, classLoader, uncaughtExceptionHandler, threadGroup, onTermination, time, this, extraInfo);
}
Also used : SerializableFunction(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableFunction) LocalTime(org.apache.cassandra.simulator.systems.SimulatedTime.LocalTime) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)

Example 2 with SerializableRunnable

use of org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable in project cassandra by apache.

the class InternodeEncryptionEnforcementTest method testConnectionsAreAcceptedWithValidConfig.

@Test
public void testConnectionsAreAcceptedWithValidConfig() throws Throwable {
    Cluster.Builder builder = builder().withNodes(2).withConfig(c -> {
        c.with(Feature.NETWORK);
        c.with(Feature.NATIVE_PROTOCOL);
        HashMap<String, Object> encryption = new HashMap<>();
        encryption.put("keystore", "test/conf/cassandra_ssl_test.keystore");
        encryption.put("keystore_password", "cassandra");
        encryption.put("truststore", "test/conf/cassandra_ssl_test.truststore");
        encryption.put("truststore_password", "cassandra");
        encryption.put("internode_encryption", "dc");
        c.set("server_encryption_options", encryption);
    }).withNodeIdTopology(ImmutableMap.of(1, NetworkTopology.dcAndRack("dc1", "r1a"), 2, NetworkTopology.dcAndRack("dc2", "r2a")));
    try (Cluster cluster = builder.start()) {
        openConnections(cluster);
        /*
             * instance (1) should connect to instance (2) without any issues;
             * instance (2) should connect to instance (1) without any issues.
             */
        SerializableRunnable runnable = () -> {
            InboundMessageHandlers inbound = getOnlyElement(MessagingService.instance().messageHandlers.values());
            assertTrue(inbound.count() > 0);
            OutboundConnections outbound = getOnlyElement(MessagingService.instance().channelManagers.values());
            assertTrue(outbound.small.isConnected() || outbound.large.isConnected() || outbound.urgent.isConnected());
        };
        cluster.get(1).runOnInstance(runnable);
        cluster.get(2).runOnInstance(runnable);
    }
}
Also used : MessagingService(org.apache.cassandra.net.MessagingService) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) OutboundConnections(org.apache.cassandra.net.OutboundConnections) Assert.assertThat(org.junit.Assert.assertThat) Assert.assertFalse(org.junit.Assert.assertFalse) Cluster(org.apache.cassandra.distributed.Cluster) Assert.fail(org.junit.Assert.fail) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) OutboundConnections(org.apache.cassandra.net.OutboundConnections) HashMap(java.util.HashMap) SerializableRunnable(org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable) Cluster(org.apache.cassandra.distributed.Cluster) InboundMessageHandlers(org.apache.cassandra.net.InboundMessageHandlers) Test(org.junit.Test)

Aggregations

SerializableRunnable (org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableRunnable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 HashMap (java.util.HashMap)1 Cluster (org.apache.cassandra.distributed.Cluster)1 Feature (org.apache.cassandra.distributed.api.Feature)1 SerializableFunction (org.apache.cassandra.distributed.api.IIsolatedExecutor.SerializableFunction)1 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)1 InboundMessageHandlers (org.apache.cassandra.net.InboundMessageHandlers)1 MessagingService (org.apache.cassandra.net.MessagingService)1 OutboundConnections (org.apache.cassandra.net.OutboundConnections)1 LocalTime (org.apache.cassandra.simulator.systems.SimulatedTime.LocalTime)1 UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1