use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class PDClientTest method testGetRegionById.
@Test
public void testGetRegionById() throws Exception {
byte[] startKey = new byte[] { 1, 0, 2, 4 };
byte[] endKey = new byte[] { 1, 0, 2, 5 };
int confVer = 1026;
int ver = 1027;
pdServer.addGetRegionByIDResp(GrpcUtils.makeGetRegionResponse(pdServer.getClusterId(), GrpcUtils.makeRegion(1, encodeKey(startKey), encodeKey(endKey), GrpcUtils.makeRegionEpoch(confVer, ver), GrpcUtils.makePeer(1, 10), GrpcUtils.makePeer(2, 20))));
try (PDClient client = session.getPDClient()) {
TiRegion r = client.getRegionByID(defaultBackOff(), 0);
assertEquals(r.getStartKey(), ByteString.copyFrom(startKey));
assertEquals(r.getEndKey(), ByteString.copyFrom(endKey));
assertEquals(r.getRegionEpoch().getConfVer(), confVer);
assertEquals(r.getRegionEpoch().getVersion(), ver);
assertEquals(r.getLeader().getId(), 1);
assertEquals(r.getLeader().getStoreId(), 10);
}
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class RegionManagerTest method getStoreByKey.
@Test
public void getStoreByKey() {
ByteString startKey = ByteString.copyFrom(new byte[] { 1 });
ByteString endKey = ByteString.copyFrom(new byte[] { 10 });
ByteString searchKey = ByteString.copyFrom(new byte[] { 5 });
String testAddress = "testAddress";
long storeId = 233;
int confVer = 1026;
int ver = 1027;
long regionId = 233;
pdServer.addGetRegionResp(GrpcUtils.makeGetRegionResponse(pdServer.getClusterId(), GrpcUtils.makeRegion(regionId, GrpcUtils.encodeKey(startKey.toByteArray()), GrpcUtils.encodeKey(endKey.toByteArray()), GrpcUtils.makeRegionEpoch(confVer, ver), GrpcUtils.makePeer(storeId, 10), GrpcUtils.makePeer(storeId + 1, 20))));
pdServer.addGetStoreResp(GrpcUtils.makeGetStoreResponse(pdServer.getClusterId(), GrpcUtils.makeStore(storeId, testAddress, Metapb.StoreState.Up, GrpcUtils.makeStoreLabel("k1", "v1"), GrpcUtils.makeStoreLabel("k2", "v2"))));
Pair<TiRegion, Store> pair = mgr.getRegionStorePairByKey(searchKey);
assertEquals(pair.first.getId(), regionId);
assertEquals(pair.first.getId(), storeId);
}
use of com.pingcap.tikv.region.TiRegion in project tispark by pingcap.
the class LockResolverSITest method cleanLockTest.
@Test
public void cleanLockTest() {
if (!init) {
skipTestInit();
return;
}
for (int i = 0; i < 26; i++) {
String k = String.valueOf((char) ('a' + i));
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
assertTrue(lockKey(k, k, k, k, false, startTs.getVersion(), endTs.getVersion()));
}
List<Mutation> mutations = new ArrayList<>();
List<String> keys = new ArrayList<>();
for (int i = 0; i < 26; i++) {
String k = String.valueOf((char) ('a' + i));
String v = String.valueOf((char) ('a' + i + 1));
Mutation m = Mutation.newBuilder().setKey(ByteString.copyFromUtf8(k)).setOp(Op.Put).setValue(ByteString.copyFromUtf8(v)).build();
mutations.add(m);
keys.add(k);
}
TiTimestamp startTs = session.getTimestamp();
TiTimestamp endTs = session.getTimestamp();
boolean res = prewriteString(mutations, startTs.getVersion(), mutations.get(0).getKey().toStringUtf8(), DEFAULT_TTL);
assertTrue(res);
res = commitString(keys, startTs.getVersion(), endTs.getVersion());
assertTrue(res);
for (int i = 0; i < 26; i++) {
TiRegion tiRegion = session.getRegionManager().getRegionByKey(ByteString.copyFromUtf8(String.valueOf((char) ('a' + i))));
RegionStoreClient client = builder.build(tiRegion);
BackOffer backOffer = ConcreteBackOffer.newGetBackOff();
ByteString v = client.get(backOffer, ByteString.copyFromUtf8(String.valueOf((char) ('a' + i))), session.getTimestamp().getVersion());
assertEquals(v.toStringUtf8(), String.valueOf((char) ('a' + i + 1)));
}
}
Aggregations