|
1 | 1 | package org.tikv.raw; |
2 | 2 |
|
3 | | -import static org.junit.Assert.*; |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotNull; |
| 5 | +import static org.junit.Assert.assertNull; |
| 6 | +import static org.junit.Assert.assertTrue; |
4 | 7 |
|
| 8 | +import com.google.common.collect.ImmutableList; |
5 | 9 | import com.google.protobuf.ByteString; |
6 | 10 | import java.io.IOException; |
7 | | -import java.util.*; |
8 | | -import java.util.concurrent.*; |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.Arrays; |
| 13 | +import java.util.Comparator; |
| 14 | +import java.util.HashMap; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Locale; |
| 17 | +import java.util.Map; |
| 18 | +import java.util.Random; |
| 19 | +import java.util.TreeMap; |
| 20 | +import java.util.concurrent.ExecutionException; |
| 21 | +import java.util.concurrent.ExecutorCompletionService; |
| 22 | +import java.util.concurrent.ExecutorService; |
| 23 | +import java.util.concurrent.Executors; |
| 24 | +import java.util.concurrent.TimeUnit; |
| 25 | +import java.util.concurrent.TimeoutException; |
9 | 26 | import java.util.stream.Collectors; |
10 | 27 | import org.apache.commons.lang3.RandomStringUtils; |
11 | 28 | import org.junit.After; |
| 29 | +import org.junit.Assert; |
12 | 30 | import org.junit.Before; |
13 | 31 | import org.junit.Test; |
14 | 32 | import org.slf4j.Logger; |
|
28 | 46 | import org.tikv.kvproto.Kvrpcpb; |
29 | 47 |
|
30 | 48 | public class RawKVClientTest extends BaseRawKVTest { |
| 49 | + |
31 | 50 | private static final String RAW_PREFIX = "raw_\u0001_"; |
32 | 51 | private static final int KEY_POOL_SIZE = 1000000; |
33 | 52 | private static final int TEST_CASES = 10000; |
@@ -360,6 +379,40 @@ private List<Kvrpcpb.KvPair> rawKeys() { |
360 | 379 | return client.scan(RAW_START_KEY, RAW_END_KEY); |
361 | 380 | } |
362 | 381 |
|
| 382 | + @Test |
| 383 | + public void scanTestForIssue540() { |
| 384 | + ByteString splitKeyA = ByteString.copyFromUtf8("splitKeyA"); |
| 385 | + ByteString splitKeyB = ByteString.copyFromUtf8("splitKeyB"); |
| 386 | + int splitRegionBackoffMS = 12000; |
| 387 | + int scatterRegionBackoffMS = 30000; |
| 388 | + int scatterWaitMS = 300000; |
| 389 | + session.splitRegionAndScatter( |
| 390 | + ImmutableList.of(splitKeyA.toByteArray(), splitKeyB.toByteArray()), |
| 391 | + splitRegionBackoffMS, |
| 392 | + scatterRegionBackoffMS, |
| 393 | + scatterWaitMS); |
| 394 | + client.deleteRange(ByteString.EMPTY, ByteString.EMPTY); |
| 395 | + |
| 396 | + client.put(ByteString.EMPTY, ByteString.EMPTY); |
| 397 | + client.put(splitKeyA, ByteString.EMPTY); |
| 398 | + Assert.assertEquals(0, client.scan(ByteString.EMPTY, 0).size()); |
| 399 | + Assert.assertEquals(1, client.scan(ByteString.EMPTY, 1).size()); |
| 400 | + Assert.assertEquals(2, client.scan(ByteString.EMPTY, 2).size()); |
| 401 | + Assert.assertEquals(2, client.scan(ByteString.EMPTY, 3).size()); |
| 402 | + |
| 403 | + client.deleteRange(ByteString.EMPTY, ByteString.EMPTY); |
| 404 | + |
| 405 | + client.put(ByteString.EMPTY, ByteString.EMPTY); |
| 406 | + client.put(splitKeyA, ByteString.EMPTY); |
| 407 | + client.put(splitKeyA.concat(ByteString.copyFromUtf8("1")), ByteString.EMPTY); |
| 408 | + client.put(splitKeyA.concat(ByteString.copyFromUtf8("2")), ByteString.EMPTY); |
| 409 | + client.put(splitKeyA.concat(ByteString.copyFromUtf8("3")), ByteString.EMPTY); |
| 410 | + client.put(splitKeyB.concat(ByteString.copyFromUtf8("1")), ByteString.EMPTY); |
| 411 | + Assert.assertEquals(6, client.scan(ByteString.EMPTY, 7).size()); |
| 412 | + Assert.assertEquals(0, client.scan(ByteString.EMPTY, -1).size()); |
| 413 | + client.deleteRange(ByteString.EMPTY, ByteString.EMPTY); |
| 414 | + } |
| 415 | + |
363 | 416 | @Test |
364 | 417 | public void validate() { |
365 | 418 | baseTest(100, 100, 100, 100, false, false, false, false, false); |
@@ -449,7 +502,9 @@ private void prepare() { |
449 | 502 | int i = cnt; |
450 | 503 | completionService.submit( |
451 | 504 | () -> { |
452 | | - for (int j = 0; j < base; j++) checkDelete(remainingKeys.get(i * base + j).getKey()); |
| 505 | + for (int j = 0; j < base; j++) { |
| 506 | + checkDelete(remainingKeys.get(i * base + j).getKey()); |
| 507 | + } |
453 | 508 | return null; |
454 | 509 | }); |
455 | 510 | } |
@@ -942,6 +997,7 @@ private static ByteString rawValue(String value) { |
942 | 997 | } |
943 | 998 |
|
944 | 999 | private static class ByteStringComparator implements Comparator<ByteString> { |
| 1000 | + |
945 | 1001 | @Override |
946 | 1002 | public int compare(ByteString startKey, ByteString endKey) { |
947 | 1003 | return FastByteComparisons.compareTo(startKey.toByteArray(), endKey.toByteArray()); |
|
0 commit comments