Skip to content

Commit

Permalink
[#18233] Initial commit for yugabyted unit test framework.
Browse files Browse the repository at this point in the history
Summary: Initial commit for yugabyted unit test framework. Adding support for MiniYugabytedCluster.

Test Plan: ./yb_build.sh --java-test 'org.yb.yugabyted.TestYugabytedMasterStatus#testSingleLeader'

Reviewers: sgarg-yb, shikhar.sahay

Reviewed By: sgarg-yb, shikhar.sahay

Subscribers: yugabyted-dev

Differential Revision: https://phorge.dev.yugabyte.com/D35863
  • Loading branch information
nchandrappa committed Jun 25, 2024
1 parent b60438e commit acf11d8
Show file tree
Hide file tree
Showing 11 changed files with 1,507 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/yugabyted
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ OS_NAME = OS_DETAILS[0]
# Script constants.
SCRIPT_NAME = os.path.basename(__file__)
YUGABYTE_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
YUGABYTE_JENKINS_BUILD_DIR = os.getenv("BUILD_ROOT",
os.path.dirname(
os.path.dirname(os.path.realpath(__file__))))
TRUE_CHOICES = ["true", "True", "t", "T", "yes", "Yes", "y", "Y", "1"]
FALSE_CHOICES = ["false", "False", "f", "F", "no", "No", "n", "N", "0"]
BOOL_CHOICES = TRUE_CHOICES + FALSE_CHOICES
Expand Down Expand Up @@ -424,6 +427,15 @@ def find_binary_location(binary_name):
os.path.join(YUGABYTE_DIR, "build", "latest", "gobin"),
]

# Jenkins Test Environment
dir_candidates += [
os.path.join(YUGABYTE_JENKINS_BUILD_DIR, "bin")
]

dir_candidates += [
os.path.join(YUGABYTE_JENKINS_BUILD_DIR, "gobin")
]

return search_file_in_paths(dir_candidates, binary_name)

# Extract or Download YBC package
Expand Down
1 change: 1 addition & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<module>yb-multiapi</module>
<module>yb-sample</module>
<module>yb-ysql-conn-mgr</module>
<module>yb-yugabyted</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public String shortStr() {
public String humanReadableName() {
return "yb controller server";
}
},
YUGABYTED {

@Override
public String shortStr() {
return "ybd";
}

@Override
public String humanReadableName() {
return "yugabyted";
}
};

abstract String shortStr();
Expand Down
68 changes: 68 additions & 0 deletions java/yb-yugabyted/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.yb</groupId>
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.89-SNAPSHOT</version>
</parent>
<artifactId>yb-yugabyted</artifactId>
<version>0.8.89-SNAPSHOT</version>

<name>yb-yugabyted</name>
<!-- FIXME change it to the project's website -->
<url>https://www.yugabyte.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>${junit.groupId}</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<version>0.8.89-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-pgsql</artifactId>
<version>0.8.89-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-pgsql</artifactId>
<version>0.8.89-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package org.yb.minicluster;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yb.BaseYBTest;
import org.yb.client.TestUtils;
import org.yb.util.Timeouts;

import com.google.common.net.HostAndPort;

public class BaseMiniYugabytedClusterTest extends BaseYBTest {

private static final Logger LOG = LoggerFactory.getLogger(BaseMiniYugabytedClusterTest.class);

/** Default timeout used when calling YB Java client's async API. */
protected static final int DEFAULT_SLEEP = (int) Timeouts.adjustTimeoutSecForBuildType(50000);

/**
* Whether the fresh cluster should be created for the next test, so that custom
* {@code createMiniCluster} won't affect other tests.
*/
private static boolean clusterNeedsRecreation = false;

/**
* A mini-cluster shared between invocations of multiple test methods.
*/
protected static MiniYugabytedCluster miniYugabytedCluster;

/**
* Comma separate describing the master addresses and ports.
*/
protected static String masterAddresses;

protected static List<HostAndPort> masterHostPorts;

protected String certFile = null;

// The client cert files for mTLS.
protected String clientCertFile = null;
protected String clientKeyFile = null;

/** Default bind address (Used only for mTLS verification). */
protected String clientHost = null;
protected int clientPort = 0;

@Before
public void setUpBefore() throws Exception {
resetSettings();
if (!isMiniClusterEnabled()) {
return;
}
TestUtils.clearReservedPorts();
if (clusterNeedsRecreation) {
destroyMiniCluster();
clusterNeedsRecreation = false;
}
if (miniYugabytedCluster == null) {
createMiniCluster(1);
} else if (shouldRestartMiniClusterBetweenTests()) {
LOG.info("Restarting the MiniCluster");
miniYugabytedCluster.restart();
}
}

protected final void createMiniCluster(int numNodes) throws Exception {
createMiniYugabytedCluster(numNodes);
}

protected final void createMiniYugabytedCluster(int numNodes) throws Exception {

if (!isMiniClusterEnabled()) {
return;
}

final int replicationFactor = getReplicationFactor();

MiniYugabytedClusterParameters clusterParameters = new MiniYugabytedClusterParameters();

// miniYugabytedCluster = new MiniYugabytedCluster(clusterParameters,
// getMasterFlags(), getMasterFlags(), getTServerFlags(),
// null, getMasterFlags(), clientHost, certFile,
// clientCertFile, clientKeyFile);

// TO-DO: replace all nulls with the actual fields.
miniYugabytedCluster = new MiniYugabytedCluster(clusterParameters,
null, null, null,
null, null, null, null,
null, null, null);

masterAddresses = miniYugabytedCluster.getMasterAddresses();
masterHostPorts = miniYugabytedCluster.getMasterHostPorts();

afterStartingMiniCluster();

}

protected int getReplicationFactor() {
return -1;
}

protected void resetSettings() {
}

/**
* This allows subclasses to optionally skip the usage of a mini-cluster in a
* test.
*/
protected boolean isMiniClusterEnabled() {
return true;
}

protected static void destroyMiniCluster() throws Exception {
if (miniYugabytedCluster != null) {
LOG.info("Destroying mini cluster");
miniYugabytedCluster.shutdown();
miniYugabytedCluster = null;
}
}

protected boolean shouldRestartMiniClusterBetweenTests() {
return false;
}

/**
* This is called every time right after starting a mini cluster.
*/
protected void afterStartingMiniCluster() throws Exception {
}

protected Map<String, String> getYugabytedFlags() {
return new TreeMap<>();
}

protected Map<String, String> getMasterFlags() {
return new TreeMap<>();
}

protected Map<String, String> getTserverFlags() {
return new TreeMap<>();
}

}
Loading

0 comments on commit acf11d8

Please sign in to comment.