mirror of https://github.com/tikv/client-java.git
ignore ci test with TxnKV (#281)
Signed-off-by: marsishandsome <marsishandsome@gmail.com>
This commit is contained in:
parent
869124880e
commit
dcea3b305c
|
|
@ -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) {
|
||||
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
README.md
14
README.md
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
# TiDB Configuration.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# TiKV Configuration.
|
||||
|
||||
[raftstore]
|
||||
# set store capacity, if no set, use disk capacity.
|
||||
capacity = "8G"
|
||||
|
|
@ -267,7 +267,7 @@ public class TiConfiguration implements Serializable {
|
|||
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);
|
||||
|
|
@ -624,6 +624,10 @@ public class TiConfiguration implements Serializable {
|
|||
return this.enableGrpcForward;
|
||||
}
|
||||
|
||||
public void setEnableGrpcForward(boolean enableGrpcForward) {
|
||||
this.enableGrpcForward = enableGrpcForward;
|
||||
}
|
||||
|
||||
public long getGrpcHealthCheckTimeout() {
|
||||
return this.grpcHealthCheckTimeout;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,14 @@ import static org.junit.Assert.assertTrue;
|
|||
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);
|
||||
}
|
||||
|
|
@ -30,11 +31,11 @@ public class PDClientIntegrationTest {
|
|||
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));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.tikv.common;
|
|||
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;
|
||||
|
|
@ -37,7 +36,7 @@ import org.tikv.kvproto.Metapb;
|
|||
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://";
|
||||
|
|
@ -88,8 +87,8 @@ public class PDClientTest extends PDMockServerTest {
|
|||
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))));
|
||||
|
|
@ -119,8 +118,8 @@ public class PDClientTest extends PDMockServerTest {
|
|||
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))));
|
||||
|
|
@ -40,7 +40,10 @@ public abstract class PDMockServerTest {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ package org.tikv.common;
|
|||
|
||||
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;
|
||||
|
|
@ -59,7 +58,6 @@ public class RegionManagerTest extends PDMockServerTest {
|
|||
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;
|
||||
|
|
@ -91,10 +89,6 @@ public class RegionManagerTest extends PDMockServerTest {
|
|||
|
||||
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
|
||||
|
|
@ -160,12 +154,5 @@ public class RegionManagerTest extends PDMockServerTest {
|
|||
GrpcUtils.makeStoreLabel("k1", "v1"),
|
||||
GrpcUtils.makeStoreLabel("k2", "v2"))));
|
||||
assertNull(mgr.getStoreById(storeId + 1));
|
||||
|
||||
mgr.invalidateStore(storeId);
|
||||
try {
|
||||
mgr.getStoreById(storeId);
|
||||
fail();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
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
|
||||
|
|
@ -38,8 +39,7 @@ public class TiSessionTest {
|
|||
}
|
||||
|
||||
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();
|
||||
|
|
@ -83,8 +83,7 @@ public class TiSessionTest {
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.Optional;
|
|||
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;
|
||||
|
|
@ -18,7 +19,7 @@ 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;
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ import java.util.List;
|
|||
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;
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ package org.tikv.common.importer;
|
|||
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;
|
||||
|
||||
public class SwitchTiKVModeTest {
|
||||
public class SwitchTiKVModeTest extends BaseRawKVTest {
|
||||
private TiSession session;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
session = TiSession.create(conf);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.tikv.BaseTxnKVTest;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.common.key.Key;
|
||||
|
|
@ -15,7 +16,7 @@ import org.tikv.common.util.Pair;
|
|||
import org.tikv.txn.KVClient;
|
||||
import org.tikv.util.TestUtils;
|
||||
|
||||
public class TxnKVIngestTest {
|
||||
public class TxnKVIngestTest extends BaseTxnKVTest {
|
||||
private TiSession session;
|
||||
|
||||
private static final int KEY_NUMBER = 16;
|
||||
|
|
@ -25,8 +26,7 @@ public class TxnKVIngestTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
TiConfiguration conf = TiConfiguration.createDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
session = TiSession.create(conf);
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ public class TxnKVIngestTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void txnIngestTest() {
|
||||
KVClient client = session.createKVClient();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tikv.BaseRawKVTest;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.common.exception.RawCASConflictException;
|
||||
|
||||
public class CASTest {
|
||||
public class CASTest extends BaseRawKVTest {
|
||||
private RawKVClient client;
|
||||
private boolean initialized;
|
||||
private static final Logger logger = LoggerFactory.getLogger(RawKVClientTest.class);
|
||||
|
|
@ -24,8 +25,7 @@ public class CASTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
conf.setEnableAtomicForCAS(true);
|
||||
session = TiSession.create(conf);
|
||||
initialized = false;
|
||||
|
|
@ -48,7 +48,6 @@ public class CASTest {
|
|||
|
||||
@Test
|
||||
public void rawCASTest() {
|
||||
if (!initialized) return;
|
||||
ByteString key = ByteString.copyFromUtf8("key_atomic");
|
||||
ByteString value = ByteString.copyFromUtf8("value");
|
||||
ByteString value2 = ByteString.copyFromUtf8("value2");
|
||||
|
|
@ -65,7 +64,6 @@ public class CASTest {
|
|||
|
||||
@Test
|
||||
public void rawPutIfAbsentTest() {
|
||||
if (!initialized) return;
|
||||
long ttl = 10;
|
||||
ByteString key = ByteString.copyFromUtf8("key_atomic");
|
||||
ByteString value = ByteString.copyFromUtf8("value");
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.tikv.BaseRawKVTest;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
|
||||
public class MetricsTest {
|
||||
public class MetricsTest extends BaseRawKVTest {
|
||||
private final List<TiSession> sessionList = new ArrayList<>();
|
||||
|
||||
@After
|
||||
|
|
@ -26,8 +27,7 @@ public class MetricsTest {
|
|||
|
||||
@Test
|
||||
public void oneTiSession() throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
conf.setMetricsEnable(true);
|
||||
TiSession session = TiSession.create(conf);
|
||||
sessionList.add(session);
|
||||
|
|
@ -42,8 +42,7 @@ public class MetricsTest {
|
|||
|
||||
@Test
|
||||
public void twoTiSession() throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
conf.setMetricsEnable(true);
|
||||
|
||||
TiSession session1 = TiSession.create(conf);
|
||||
|
|
@ -69,15 +68,13 @@ public class MetricsTest {
|
|||
|
||||
@Test
|
||||
public void twoTiSessionWithDifferentPort() {
|
||||
TiConfiguration conf1 = TiConfiguration.createRawDefault();
|
||||
conf1.setTest(true);
|
||||
TiConfiguration conf1 = createTiConfiguration();
|
||||
conf1.setMetricsEnable(true);
|
||||
conf1.setMetricsPort(12345);
|
||||
TiSession session1 = TiSession.create(conf1);
|
||||
sessionList.add(session1);
|
||||
|
||||
TiConfiguration conf2 = TiConfiguration.createRawDefault();
|
||||
conf2.setTest(true);
|
||||
TiConfiguration conf2 = createTiConfiguration();
|
||||
conf2.setMetricsEnable(true);
|
||||
conf2.setMetricsPort(54321);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tikv.BaseRawKVTest;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.common.codec.KeyUtils;
|
||||
|
|
@ -22,7 +23,7 @@ import org.tikv.common.util.Pair;
|
|||
import org.tikv.common.util.ScanOption;
|
||||
import org.tikv.kvproto.Kvrpcpb;
|
||||
|
||||
public class RawKVClientTest {
|
||||
public class RawKVClientTest extends BaseRawKVTest {
|
||||
private static final String RAW_PREFIX = "raw_\u0001_";
|
||||
private static final int KEY_POOL_SIZE = 1000000;
|
||||
private static final int TEST_CASES = 10000;
|
||||
|
|
@ -72,8 +73,7 @@ public class RawKVClientTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
session = TiSession.create(conf);
|
||||
initialized = false;
|
||||
if (client == null) {
|
||||
|
|
@ -96,7 +96,6 @@ public class RawKVClientTest {
|
|||
|
||||
@Test
|
||||
public void getKeyTTLTest() {
|
||||
if (!initialized) return;
|
||||
long ttl = 10;
|
||||
ByteString key = ByteString.copyFromUtf8("key_ttl");
|
||||
ByteString value = ByteString.copyFromUtf8("value");
|
||||
|
|
@ -139,7 +138,6 @@ public class RawKVClientTest {
|
|||
|
||||
@Test
|
||||
public void batchPutTest() {
|
||||
if (!initialized) return;
|
||||
ExecutorService executors = Executors.newFixedThreadPool(200);
|
||||
ExecutorCompletionService<Object> completionService =
|
||||
new ExecutorCompletionService<>(executors);
|
||||
|
|
@ -228,13 +226,11 @@ public class RawKVClientTest {
|
|||
|
||||
@Test
|
||||
public void deleteRangeTest() {
|
||||
if (!initialized) return;
|
||||
client.deleteRange(ByteString.EMPTY, ByteString.EMPTY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest() {
|
||||
if (!initialized) return;
|
||||
ByteString key = rawKey("key");
|
||||
ByteString key0 = rawKey("key0");
|
||||
ByteString key1 = rawKey("key1");
|
||||
|
|
@ -288,14 +284,12 @@ public class RawKVClientTest {
|
|||
|
||||
@Test
|
||||
public void validate() {
|
||||
if (!initialized) return;
|
||||
baseTest(100, 100, 100, 100, false, false, false, false, false);
|
||||
baseTest(100, 100, 100, 100, false, true, true, true, true);
|
||||
}
|
||||
|
||||
/** Example of benchmarking base test */
|
||||
public void benchmark() {
|
||||
if (!initialized) return;
|
||||
baseTest(TEST_CASES, TEST_CASES, 200, 5000, true, false, false, false, false);
|
||||
baseTest(TEST_CASES, TEST_CASES, 200, 5000, true, true, true, true, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.junit.After;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.common.replica.Region;
|
||||
|
|
@ -18,7 +19,7 @@ public class ReplicaReadTest extends TXNTest {
|
|||
private String key;
|
||||
private String value;
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void leaderReadTest() {
|
||||
doTest(TiConfiguration.ReplicaRead.LEADER);
|
||||
}
|
||||
|
|
@ -29,15 +30,14 @@ public class ReplicaReadTest extends TXNTest {
|
|||
doTest(TiConfiguration.ReplicaRead.FOLLOWER);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void leadAndFollowerReadTest() {
|
||||
doTest(TiConfiguration.ReplicaRead.LEADER_AND_FOLLOWER);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void replicaSelectorTest() {
|
||||
TiConfiguration conf = TiConfiguration.createDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
|
||||
conf.setReplicaSelector(
|
||||
new ReplicaSelector() {
|
||||
|
|
@ -58,8 +58,7 @@ public class ReplicaReadTest extends TXNTest {
|
|||
}
|
||||
|
||||
private void doTest(TiConfiguration.ReplicaRead replicaRead) {
|
||||
TiConfiguration conf = TiConfiguration.createDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
conf.setReplicaRead(replicaRead);
|
||||
session = TiSession.create(conf);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||
import java.util.stream.Collectors;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.tikv.BaseTxnKVTest;
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.common.exception.RegionException;
|
||||
|
|
@ -21,15 +22,14 @@ import org.tikv.common.util.BackOffer;
|
|||
import org.tikv.common.util.ConcreteBackOffer;
|
||||
import org.tikv.kvproto.Kvrpcpb;
|
||||
|
||||
public class TXNTest {
|
||||
public class TXNTest extends BaseTxnKVTest {
|
||||
static final int DEFAULT_TTL = 10;
|
||||
private TiSession session;
|
||||
RegionStoreClient.RegionStoreClientBuilder builder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
TiConfiguration conf = TiConfiguration.createDefault();
|
||||
conf.setTest(true);
|
||||
TiConfiguration conf = createTiConfiguration();
|
||||
try {
|
||||
session = TiSession.create(conf);
|
||||
this.builder = session.getRegionStoreClientBuilder();
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright 2017 PingCAP, Inc.
|
||||
*
|
||||
* Licensed 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,
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.tikv.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReflectionWrapper {
|
||||
public ReflectionWrapper(Object obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
private final Object obj;
|
||||
|
||||
public Object call(String methodName, Object... args) {
|
||||
try {
|
||||
Method method = obj.getClass().getDeclaredMethod(methodName);
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj, args);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,20 @@ import java.util.Random;
|
|||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class TestUtils {
|
||||
public static String getEnv(String key) {
|
||||
String tmp = System.getenv(key);
|
||||
if (tmp != null && !tmp.equals("")) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
tmp = System.getProperty(key);
|
||||
if (tmp != null && !tmp.equals("")) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte[] genRandomKey(String keyPrefix, int keyLength) {
|
||||
int length = keyLength - keyPrefix.length();
|
||||
if (length <= 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue