Skip to content
Permalink
Browse files
Introduce the extracted in-JVM DTest API
Patch by Alex Petrov; reviewed by David Capwell for CASSANDRA-15539.
  • Loading branch information
ifesdjeen committed Mar 21, 2020
1 parent 68e0030 commit a562fd56b302e0573b2af9371aa948689714dcbc
Showing 27 changed files with 2,577 additions and 0 deletions.
99 pom.xml
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>23</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.cassandra</groupId>
<artifactId>dtest-api</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>In JVM Test API</name>
<description>In JVM Test API</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>in-jvm-dtest-cassandra-tryout</artifactId>
<version>0.0.1-2.2-1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>


<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</url>
<tag>0.0.4</tag>
</scm>
</project>

@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.cassandra.distributed.api;

public enum ConsistencyLevel {
ANY,
ONE,
TWO,
THREE,
QUORUM,
ALL,
LOCAL_QUORUM,
EACH_QUORUM,
SERIAL,
LOCAL_SERIAL,
LOCAL_ONE,
NODE_LOCAL
}
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.cassandra.distributed.api;

public enum Feature
{
NETWORK, GOSSIP, NATIVE_PROTOCOL
}
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.cassandra.distributed.api;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

public interface ICluster<I extends IInstance> extends AutoCloseable {
void startup();

I bootstrap(IInstanceConfig config);

I get(int i);

I get(InetSocketAddress endpoint);

ICoordinator coordinator(int node);

void schemaChange(String query);

void schemaChange(String statement, int instance);

int size();

Stream<I> stream();

Stream<I> stream(String dcName);

Stream<I> stream(String dcName, String rackName);

IMessageFilters filters();

static void setup() throws Throwable {
setupLogging();
setSystemProperties();
nativeLibraryWorkaround();
processReaperWorkaround();
}

static void nativeLibraryWorkaround() {
// Disable the Netty tcnative library otherwise the io.netty.internal.tcnative.CertificateCallbackTask,
// CertificateVerifierTask, SSLPrivateKeyMethodDecryptTask, SSLPrivateKeyMethodSignTask,
// SSLPrivateKeyMethodTask, and SSLTask hold a gcroot against the InstanceClassLoader.
System.setProperty("cassandra.disable_tcactive_openssl", "true");
System.setProperty("io.netty.transport.noNative", "true");
}

static void processReaperWorkaround() throws Throwable {
// Make sure the 'process reaper' thread is initially created under the main classloader,
// otherwise it gets created with the contextClassLoader pointing to an InstanceClassLoader
// which prevents it from being garbage collected.
new ProcessBuilder().command("true").start().waitFor();
}

static void setSystemProperties() {
System.setProperty("cassandra.ring_delay_ms", Integer.toString(30 * 1000));
System.setProperty("org.apache.cassandra.disable_mbean_registration", "true");
}

static void setupLogging() {
try {
File root = Files.createTempDirectory("in-jvm-dtest").toFile();
root.deleteOnExit();
String testConfPath = "test/conf/logback-dtest.xml";
Path logConfPath = Paths.get(root.getPath(), "/logback-dtest.xml");

if (!logConfPath.toFile().exists()) {
Files.copy(new File(testConfPath).toPath(),
logConfPath);
}

System.setProperty("logback.configurationFile", "file://" + logConfPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.cassandra.distributed.api;

import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.Future;

// The cross-version API requires that a Coordinator can be constructed without any constructor arguments
public interface ICoordinator
{
default Object[][] execute(String query, ConsistencyLevel consistencyLevel, Object... boundValues)
{
return executeWithResult(query, consistencyLevel, boundValues).toObjectArrays();
}
QueryResult executeWithResult(String query, ConsistencyLevel consistencyLevel, Object... boundValues);
Iterator<Object[]> executeWithPaging(String query, ConsistencyLevel consistencyLevel, int pageSize, Object... boundValues);

Future<Object[][]> asyncExecuteWithTracing(UUID sessionId, String query, ConsistencyLevel consistencyLevel, Object... boundValues);
Object[][] executeWithTracing(UUID sessionId, String query, ConsistencyLevel consistencyLevel, Object... boundValues);
IInstance instance();
}
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.cassandra.distributed.api;

import java.net.InetSocketAddress;
import java.util.UUID;
import java.util.concurrent.Future;

// The cross-version API requires that an Instance has a constructor signature of (IInstanceConfig, ClassLoader)
public interface IInstance extends IIsolatedExecutor
{
ICoordinator coordinator();
IListen listen();

void schemaChangeInternal(String query);
public Object[][] executeInternal(String query, Object... args);

IInstanceConfig config();
InetSocketAddress broadcastAddress();
UUID schemaVersion();

void startup();
boolean isShutdown();
Future<Void> shutdown();
Future<Void> shutdown(boolean graceful);

int liveMemberCount();

NodeToolResult nodetoolResult(boolean withNotifications, String... commandAndArgs);
default NodeToolResult nodetoolResult(String... commandAndArgs)
{
return nodetoolResult(true, commandAndArgs);
}
default int nodetool(String... commandAndArgs) {
return nodetoolResult(commandAndArgs).getRc();
}
void uncaughtException(Thread t, Throwable e);

/**
* Return the number of times the instance tried to call {@link System#exit(int)}.
*
* When the instance is shutdown, this state should be saved, but in case not possible should return {@code -1}
* to indicate "unknown".
*/
long killAttempts();

// these methods are not for external use, but for simplicity we leave them public and on the normal IInstance interface
void startup(ICluster cluster);
void receiveMessage(IMessage message);

int getMessagingVersion();
void setMessagingVersion(InetSocketAddress addressAndPort, int version);

void flush(String keyspace);
void forceCompact(String keyspace, String table);
}

0 comments on commit a562fd5

Please sign in to comment.