Skip to content

Commit dde3778

Browse files
committed
feat : change test case
1 parent 4d31ce3 commit dde3778

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/TableMapEventMetadataDeserializer.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int n
6969
switch (fieldType) {
7070
case SIGNEDNESS:
7171
result.setSignedness(
72-
convertColumnOrder(readBooleanList(inputStream, nNumericColumns), nColumns,
72+
convertAllColumnOrder(readBooleanList(inputStream, nNumericColumns), nColumns,
7373
numericColumIdxList));
7474
break;
7575
case DEFAULT_CHARSET:
@@ -113,21 +113,19 @@ public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int n
113113
return result;
114114
}
115115

116-
private static BitSet convertColumnOrder(BitSet numericOrderBitSet, int nColumns,
116+
private static BitSet convertAllColumnOrder(BitSet numericOrderBitSet, int nColumns,
117117
List<Integer> numericColumIdxList) {
118118
// Case SIGNEDNESS The order of indices in the Inputstream corresponds to the order of numeric columns
119119
// So we need to change the index to all columns index (include non numeric type columns)
120-
121120
BitSet columnOrderBitSet = new BitSet();
122121
int position = 0;
123122
for (int columnIndex = 0; columnIndex < nColumns; columnIndex++) {
124-
if (numericColumIdxList.contains(columnIndex)) {
125-
if (numericOrderBitSet.get(position++)) {
126-
columnOrderBitSet.set(columnIndex);
127-
}
128-
123+
if (!numericColumIdxList.contains(columnIndex)) {
124+
continue;
125+
}
126+
if (numericOrderBitSet.get(position++)) {
127+
columnOrderBitSet.set(columnIndex);
129128
}
130-
131129
}
132130
return columnOrderBitSet;
133131
}

src/test/java/com/github/shyiko/mysql/binlog/event/deserialization/TableMapEventMetadataDeserializerTest.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.shyiko.mysql.binlog.event.TableMapEventMetadata;
44
import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream;
5+
56
import org.testng.annotations.Test;
67

78
import java.io.IOException;
@@ -29,26 +30,35 @@ public class TableMapEventMetadataDeserializerTest {
2930
*/
3031
@Test
3132
public void deserialize() throws IOException {
32-
byte[] metadataIncludingUnknownFieldType = {1, 2, -1, 2, 9, 83, 6, 63, 7, 63, 8, 63, 9, 63};
33+
byte[] metadataIncludingUnknownFieldType = { 1, 1, 29, 2, 9, 83, 6, 63, 7, 63, 8, 63, 9, 63 };
3334
TableMapEventMetadataDeserializer deserializer = new TableMapEventMetadataDeserializer();
3435
// suppose there Columns idx likes
35-
// col 0, 2, 4, 6, 7, 9, 11, 13 unsigned
36-
// col 1 ,3 ..., 22 signed or non numeric
37-
List<Integer> numericIndexWithAllColumn = Arrays.asList(0, 2, 4, 6, 7, 9, 11, 13);
36+
// col 0, 1, 10, 11,,, non numeric
37+
// col 2, 3, 4, 8 signed
38+
// col 5, 6, 7, 9 unsigned
39+
List<Integer> numericIndexWithAllColumn = Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9);
3840
TableMapEventMetadata tableMapEventMetadata =
39-
deserializer.deserialize(new ByteArrayInputStream(metadataIncludingUnknownFieldType), 23, 8, numericIndexWithAllColumn);
41+
deserializer.deserialize(new ByteArrayInputStream(metadataIncludingUnknownFieldType), 23, 8,
42+
numericIndexWithAllColumn);
4043

4144
Map<Integer, Integer> expectedCharsetCollations = new LinkedHashMap<>();
4245
expectedCharsetCollations.put(6, 63);
4346
expectedCharsetCollations.put(7, 63);
4447
expectedCharsetCollations.put(8, 63);
4548
expectedCharsetCollations.put(9, 63);
4649

50+
// metadataIncludingUnknownFieldType[2] = 29
51+
// bin 00011101
52+
// 2, 3, 4, 5(hit), 6(hit), 7(hit), 8, 9(hit
4753
BitSet expectAllColumnBitSet = new BitSet();
48-
for(int i=0; i< numericIndexWithAllColumn.size(); i++)expectAllColumnBitSet.set(numericIndexWithAllColumn.get(i));
54+
expectAllColumnBitSet.set(5);
55+
expectAllColumnBitSet.set(6);
56+
expectAllColumnBitSet.set(7);
57+
expectAllColumnBitSet.set(9);
4958

5059
assertEquals(tableMapEventMetadata.getDefaultCharset().getDefaultCharsetCollation(), 83);
51-
assertEquals(tableMapEventMetadata.getDefaultCharset().getCharsetCollations(), expectedCharsetCollations);
60+
assertEquals(tableMapEventMetadata.getDefaultCharset().getCharsetCollations(),
61+
expectedCharsetCollations);
5262
assertEquals(tableMapEventMetadata.getSignedness(), expectAllColumnBitSet);
5363
}
5464
}

0 commit comments

Comments
 (0)