Skip to content

Commit 4c630ee

Browse files
committed
fix review: add ut for byteutil
1 parent e5762f4 commit 4c630ee

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,17 @@ public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSing
360360
false, false, obTableClient.getRoute(false));
361361
long lsId = tableObPair.getRight().getLsId();
362362

363-
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperations
363+
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperations
364364
= lsOperationsMap.computeIfAbsent(lsId, k -> new HashMap<>());
365-
// if ls id not exists
365+
// if ls id not exists
366366

367-
ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> singleOperations =
367+
ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> singleOperations =
368368
tabletOperations.computeIfAbsent(tableObPair.getLeft(), k -> new ObPair<>(tableObPair.getRight(), new ArrayList<>()));
369-
// if tablet id not exists
370-
371-
singleOperations.getRight().add(new ObPair<>(i, operation));
372-
}
369+
// if tablet id not exists
370+
singleOperations.getRight().add(new ObPair<>(i, operation));
371+
}
373372

374-
return lsOperationsMap;
373+
return lsOperationsMap;
375374
}
376375

377376
public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> partitionPrepare()
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.alipay.oceanbase.rpc.util;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import static com.alipay.oceanbase.rpc.util.ByteUtil.compareByteArrays;
7+
import static org.junit.Assert.*;
8+
9+
10+
public class ByteUtilTest {
11+
@Test
12+
public void testcompareByteArrays() {
13+
{
14+
byte[] array1 = {1, 2, 3};
15+
byte[] array2 = {1, 2, 3};
16+
Assert.assertEquals(0, compareByteArrays(array1, array2));
17+
}
18+
{
19+
byte[] array1 = {2, 2, 3};
20+
byte[] array2 = {1, 2, 3};
21+
Assert.assertTrue(compareByteArrays(array1, array2) > 0);
22+
}
23+
{
24+
byte[] array1 = {1, 2, 3, 4};
25+
byte[] array2 = {1, 2, 3};
26+
assertTrue(compareByteArrays(array1, array2) > 0);
27+
}
28+
{
29+
byte[] array1 = {};
30+
byte[] array2 = {};
31+
assertEquals(0, compareByteArrays(array1, array2));
32+
}
33+
}
34+
@Test
35+
public void testincrementByteArray() {
36+
{
37+
byte[] input = {0x01, 0x02, 0x03};
38+
byte[] expected = {0x01, 0x02, 0x04};
39+
assertArrayEquals(expected, ByteUtil.incrementByteArray(input));
40+
}
41+
{
42+
byte[] input = {(byte) 0xFF, (byte) 0xFF};
43+
byte[] expected = {0x01, 0x00, 0x00};
44+
assertArrayEquals(expected, ByteUtil.incrementByteArray(input));
45+
}
46+
{
47+
byte[] input = {};
48+
byte[] expected = {0x01};
49+
assertArrayEquals(expected, ByteUtil.incrementByteArray(input));
50+
}
51+
{
52+
byte[] expected = {0x01};
53+
assertArrayEquals(expected, ByteUtil.incrementByteArray(null));
54+
}
55+
}
56+
57+
@Test
58+
public void testdecrementByteArray() {
59+
{
60+
byte[] input = {0x01};
61+
byte[] expected = {0x00};
62+
assertArrayEquals(expected, ByteUtil.decrementByteArray(input));
63+
}
64+
{
65+
byte[] input = {0x01, 0x00};
66+
byte[] expected = {0x00, (byte) 0xFF};
67+
assertArrayEquals(expected, ByteUtil.decrementByteArray(input));
68+
}
69+
{
70+
byte[] input = {0x02, 0x00};
71+
byte[] expected = {0x01, (byte) 0xFF};
72+
assertArrayEquals(expected, ByteUtil.decrementByteArray(input));
73+
}
74+
{
75+
byte[] input = {0x01, 0x00, 0x00};
76+
byte[] expected = {0x00, (byte) 0xFF, (byte) 0xFF};
77+
assertArrayEquals(expected, ByteUtil.decrementByteArray(input));
78+
}
79+
{
80+
byte[] input = {(byte) 0xFF, (byte) 0xFF};
81+
byte[] expected = {(byte) 0xFF, (byte) 0xFE};
82+
assertArrayEquals(expected, ByteUtil.decrementByteArray(input));
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)