Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions .ci/integration_test.groovy
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
def call(ghprbActualCommit, ghprbPullId, ghprbPullTitle, ghprbPullLink, ghprbPullDescription, credentialsId) {

def TIDB_BRANCH = "master"
def TIKV_BRANCH = "master"
def PD_BRANCH = "master"

// parse tidb branch
def m1 = ghprbCommentBody =~ /tidb\s*=\s*([^\s\\]+)(\s|\\|$)/
if (m1) {
TIDB_BRANCH = "${m1[0][1]}"
}
m1 = null
println "TIDB_BRANCH=${TIDB_BRANCH}"

// parse pd branch
def m2 = ghprbCommentBody =~ /pd\s*=\s*([^\s\\]+)(\s|\\|$)/
if (m2) {
Expand Down Expand Up @@ -48,9 +39,6 @@ def call(ghprbActualCommit, ghprbPullId, ghprbPullTitle, ghprbPullLink, ghprbPul
}

dir("/home/jenkins/agent/git/client-java/_run") {
// tidb
def tidb_sha1 = sh(returnStdout: true, script: "curl ${FILE_SERVER_URL}/download/refs/pingcap/tidb/${TIDB_BRANCH}/sha1").trim()
sh "curl ${FILE_SERVER_URL}/download/builds/pingcap/tidb/${tidb_sha1}/centos7/tidb-server.tar.gz | tar xz"
// tikv
def tikv_sha1 = sh(returnStdout: true, script: "curl ${FILE_SERVER_URL}/download/refs/pingcap/tikv/${TIKV_BRANCH}/sha1").trim()
sh "curl ${FILE_SERVER_URL}/download/builds/pingcap/tikv/${tikv_sha1}/centos7/tikv-server.tar.gz | tar xz"
Expand All @@ -59,20 +47,33 @@ def call(ghprbActualCommit, ghprbPullId, ghprbPullTitle, ghprbPullLink, ghprbPul
sh "curl ${FILE_SERVER_URL}/download/builds/pingcap/pd/${pd_sha1}/centos7/pd-server.tar.gz | tar xz"

sh """
killall -9 tidb-server || true
killall -9 tikv-server || true
killall -9 pd-server || true
killall -9 java || true
sleep 10
bin/pd-server --name=pd --data-dir=pd --config=../config/pd.toml &>pd.log &
"""

sh """
echo "start TiKV for RawKV test"
bin/pd-server --name=pd_rawkv --data-dir=pd_rawkv --client-urls="http://0.0.0.0:2379" --advertise-client-urls="http://127.0.0.1:2379" --peer-urls="http://0.0.0.0:2380" --advertise-peer-urls="http://127.0.0.1:2380" --config=../config/pd.toml &>pd_rawkv.log &
sleep 10
bin/tikv-server --pd=127.0.0.1:2379 -s tikv --addr=0.0.0.0:20160 --advertise-addr=127.0.0.1:20160 --config=../config/tikv.toml &>tikv.log &
bin/tikv-server --pd 127.0.0.1:2379 --data-dir tikv_rawkv --addr 0.0.0.0:20160 --advertise-addr 127.0.0.1:20160 --status-addr 0.0.0.0:20180 --config ../config/tikv_rawkv.toml &>tikv_rawkv.log &
sleep 10
ps aux | grep '-server' || true
curl -s 127.0.0.1:2379/pd/api/v1/status || true
bin/tidb-server --store=tikv --path="127.0.0.1:2379" --config=../config/tidb.toml &>tidb.log &
sleep 60
"""

sh """
echo "start TiKV for TxnKV test"
bin/pd-server --name=pd_txnkv --data-dir=pd_txnkv --client-urls="http://0.0.0.0:3379" --advertise-client-urls="http://127.0.0.1:3379" --peer-urls="http://0.0.0.0:3380" --advertise-peer-urls="http://127.0.0.1:3380" --config=../config/pd.toml &>pd_txnkv.log &
sleep 10
bin/tikv-server --pd 127.0.0.1:3379 --data-dir tikv_txnkv --addr 0.0.0.0:21160 --advertise-addr 127.0.0.1:21160 --status-addr 0.0.0.0:21180 --config ../config/tikv_txnkv.toml &>tikv_txnkv.log &
sleep 10
ps aux | grep '-server' || true
curl -s 127.0.0.1:3379/pd/api/v1/status || true
"""

sh "sleep 30"
}
}

Expand All @@ -87,9 +88,10 @@ def call(ghprbActualCommit, ghprbPullId, ghprbPullTitle, ghprbPullLink, ghprbPul
ps aux | grep '-server' || true
curl -s 127.0.0.1:2379/pd/api/v1/status || true
"""
sh "cat _run/pd.log"
sh "cat _run/tikv.log"
sh "cat _run/tidb.log"
sh "cat _run/pd_rawkv.log"
sh "cat _run/tikv_rawkv.log"
sh "cat _run/pd_txnkv.log"
sh "cat _run/tikv_txnkv.log"
throw err
}
}
Expand Down
2 changes: 2 additions & 0 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
set -x
set -euo pipefail

export RAWKV_PD_ADDRESSES=127.0.0.1:2379
export TXNKV_PD_ADDRESSES=127.0.0.1:3379
mvn clean test
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@ It is supposed to:

## How to build

### Maven

The alternative way to build a usable jar for testing will be

```
mvn clean install -Dmaven.test.skip=true
mvn clean package -Dmaven.test.skip=true
```

The following command can install dependencies for you.
## How to run test

```
mvn package
export RAWKV_PD_ADDRESSES=127.0.0.1:2379
export TXNKV_PD_ADDRESSES=127.0.0.1:2379
mvn clean test
```

The jar can be found in `./target/`

## Usage

This project is designed to hook with [pd](https://github.com/tikv/pd) and [tikv](https://github.com/tikv/tikv).
Expand Down
1 change: 0 additions & 1 deletion config/tidb.toml

This file was deleted.

File renamed without changes.
5 changes: 5 additions & 0 deletions config/tikv_txnkv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TiKV Configuration.

[raftstore]
# set store capacity, if no set, use disk capacity.
capacity = "8G"
6 changes: 5 additions & 1 deletion src/main/java/org/tikv/common/TiConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static ReplicaRead getReplicaRead(String key) {
private boolean showRowId = getBoolean(TIKV_SHOW_ROWID);
private String dbPrefix = get(TIKV_DB_PREFIX);
private KVMode kvMode = getKvMode(TIKV_KV_MODE);
private final boolean enableGrpcForward = getBoolean(TIKV_ENABLE_GRPC_FORWARD);
private boolean enableGrpcForward = getBoolean(TIKV_ENABLE_GRPC_FORWARD);

private int kvClientConcurrency = getInt(TIKV_KV_CLIENT_CONCURRENCY);
private ReplicaRead replicaRead = getReplicaRead(TIKV_REPLICA_READ);
Expand Down Expand Up @@ -624,6 +624,10 @@ public boolean getEnableGrpcForward() {
return this.enableGrpcForward;
}

public void setEnableGrpcForward(boolean enableGrpcForward) {
this.enableGrpcForward = enableGrpcForward;
}

public long getGrpcHealthCheckTimeout() {
return this.grpcHealthCheckTimeout;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/tikv/BaseRawKVTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.tikv;

import org.tikv.common.TiConfiguration;
import org.tikv.util.TestUtils;

public class BaseRawKVTest {
protected TiConfiguration createTiConfiguration() {
String pdAddrsStr = TestUtils.getEnv("RAWKV_PD_ADDRESSES");

TiConfiguration conf =
pdAddrsStr == null
? TiConfiguration.createRawDefault()
: TiConfiguration.createRawDefault(pdAddrsStr);
conf.setTest(true);
conf.setEnableGrpcForward(false);
return conf;
}
}
18 changes: 18 additions & 0 deletions src/test/java/org/tikv/BaseTxnKVTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.tikv;

import org.tikv.common.TiConfiguration;
import org.tikv.util.TestUtils;

public class BaseTxnKVTest {
protected TiConfiguration createTiConfiguration() {
String pdAddrsStr = TestUtils.getEnv("TXNKV_PD_ADDRESSES");

TiConfiguration conf =
pdAddrsStr == null
? TiConfiguration.createDefault()
: TiConfiguration.createDefault(pdAddrsStr);
conf.setTest(true);
conf.setEnableGrpcForward(false);
return conf;
}
}
9 changes: 5 additions & 4 deletions src/test/java/org/tikv/common/PDClientIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.tikv.BaseRawKVTest;

public class PDClientIntegrationTest {
public class PDClientIntegrationTest extends BaseRawKVTest {
private TiSession session;

@Before
public void setup() {
TiConfiguration conf = TiConfiguration.createRawDefault();
TiConfiguration conf = createTiConfiguration();
conf.setTest(true);
session = TiSession.create(conf);
}
Expand All @@ -30,11 +31,11 @@ public void testPauseCheck() throws Exception {
PDChecker checker = PDChecker.Merge;
for (int i = 0; i < 2; i++) {
client.keepPauseChecker(checker);
Thread.sleep(1000);
Thread.sleep(2000);
assertTrue(client.isCheckerPaused(checker));

client.stopKeepPauseChecker(checker);
Thread.sleep(1000);
Thread.sleep(2000);

client.resumeChecker(checker);
assertFalse(client.isCheckerPaused(checker));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.tikv.common.GrpcUtils.encodeKey;

import com.google.protobuf.ByteString;
import java.util.concurrent.Callable;
Expand All @@ -37,7 +36,7 @@
import org.tikv.kvproto.Metapb.Store;
import org.tikv.kvproto.Metapb.StoreState;

public class PDClientTest extends PDMockServerTest {
public class PDClientMockTest extends PDMockServerTest {

private static final String LOCAL_ADDR_IPV6 = "[::]";
public static final String HTTP = "http://";
Expand Down Expand Up @@ -88,8 +87,8 @@ public void testGetRegionByKey() throws Exception {
pdServer.getClusterId(),
GrpcUtils.makeRegion(
1,
encodeKey(startKey),
encodeKey(endKey),
ByteString.copyFrom(startKey),
ByteString.copyFrom(endKey),
GrpcUtils.makeRegionEpoch(confVer, ver),
GrpcUtils.makePeer(1, 10),
GrpcUtils.makePeer(2, 20))));
Expand Down Expand Up @@ -119,8 +118,8 @@ public void testGetRegionById() throws Exception {
pdServer.getClusterId(),
GrpcUtils.makeRegion(
1,
encodeKey(startKey),
encodeKey(endKey),
ByteString.copyFrom(startKey),
ByteString.copyFrom(endKey),
GrpcUtils.makeRegionEpoch(confVer, ver),
GrpcUtils.makePeer(1, 10),
GrpcUtils.makePeer(2, 20))));
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/tikv/common/PDMockServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ void setUp(String addr) throws IOException {
GrpcUtils.makeMember(2, "http://" + addr + ":" + (pdServer.port + 1)),
GrpcUtils.makeMember(3, "http://" + addr + ":" + (pdServer.port + 2))));
TiConfiguration conf = TiConfiguration.createDefault(addr + ":" + pdServer.port);
conf.setEnableGrpcForward(false);
conf.setKvMode("RAW");
conf.setTest(true);
conf.setTimeout(2000);
session = TiSession.create(conf);
}

Expand Down
13 changes: 0 additions & 13 deletions src/test/java/org/tikv/common/RegionManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void getRegionByKey() {
ByteString startKey = ByteString.copyFrom(new byte[] {1});
ByteString endKey = ByteString.copyFrom(new byte[] {10});
ByteString searchKey = ByteString.copyFrom(new byte[] {5});
ByteString searchKeyNotExists = ByteString.copyFrom(new byte[] {11});
int confVer = 1026;
int ver = 1027;
long regionId = 233;
Expand Down Expand Up @@ -91,10 +89,6 @@ public void getRegionByKey() {

TiRegion regionToSearch = mgr.getRegionByKey(searchKey);
assertEquals(region, regionToSearch);

// This will in turn invoke rpc and results in an error
// since we set just one rpc response
assertNull(mgr.getRegionByKey(searchKeyNotExists));
}

@Test
Expand Down Expand Up @@ -160,12 +154,5 @@ public void getStoreById() {
GrpcUtils.makeStoreLabel("k1", "v1"),
GrpcUtils.makeStoreLabel("k2", "v2"))));
assertNull(mgr.getStoreById(storeId + 1));

mgr.invalidateStore(storeId);
try {
mgr.getStoreById(storeId);
fail();
} catch (Exception ignored) {
}
}
}
9 changes: 4 additions & 5 deletions src/test/java/org/tikv/common/TiSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.tikv.BaseRawKVTest;
import org.tikv.common.region.TiRegion;
import org.tikv.raw.RawKVClient;

public class TiSessionTest {
public class TiSessionTest extends BaseRawKVTest {
private TiSession session;

@After
Expand All @@ -38,8 +39,7 @@ public void closeAwaitTerminationWithRunningTaskTest() throws Exception {
}

private void doCloseWithRunningTaskTest(boolean now, long timeoutMS) throws Exception {
TiConfiguration conf = TiConfiguration.createRawDefault();
conf.setTest(true);
TiConfiguration conf = createTiConfiguration();
session = TiSession.create(conf);

ExecutorService executorService = session.getThreadPoolForBatchGet();
Expand Down Expand Up @@ -83,8 +83,7 @@ public void closeAwaitTerminationTest() throws Exception {
}

private void doCloseTest(boolean now, long timeoutMS) throws Exception {
TiConfiguration conf = TiConfiguration.createRawDefault();
conf.setTest(true);
TiConfiguration conf = createTiConfiguration();
session = TiSession.create(conf);
RawKVClient client = session.createRawClient();

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/tikv/common/importer/RawKVIngestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.tikv.BaseRawKVTest;
import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
import org.tikv.common.key.Key;
import org.tikv.common.util.Pair;
import org.tikv.raw.RawKVClient;
import org.tikv.util.TestUtils;

public class RawKVIngestTest {
public class RawKVIngestTest extends BaseRawKVTest {
private TiSession session;

private static final int KEY_NUMBER = 16;
Expand All @@ -28,8 +29,7 @@ public class RawKVIngestTest {

@Before
public void setup() {
TiConfiguration conf = TiConfiguration.createRawDefault();
conf.setTest(true);
TiConfiguration conf = createTiConfiguration();
session = TiSession.create(conf);
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/tikv/common/importer/RegionSplitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.tikv.BaseRawKVTest;
import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
import org.tikv.common.region.TiRegion;

public class RegionSplitTest {
public class RegionSplitTest extends BaseRawKVTest {
private TiSession session;

private static final int KEY_NUMBER = 10;
Expand All @@ -22,8 +23,7 @@ public class RegionSplitTest {

@Before
public void setup() {
TiConfiguration conf = TiConfiguration.createRawDefault();
conf.setTest(true);
TiConfiguration conf = createTiConfiguration();
session = TiSession.create(conf);
}

Expand Down
Loading