-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#18233] Initial commit for yugabyted unit test framework.
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
1 parent
b60438e
commit acf11d8
Showing
11 changed files
with
1,507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
147 changes: 147 additions & 0 deletions
147
java/yb-yugabyted/src/test/java/org/yb/minicluster/BaseMiniYugabytedClusterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} | ||
|
||
} |
Oops, something went wrong.