YvCeung commented on code in PR #7802:
URL: https://github.com/apache/incubator-seata/pull/7802#discussion_r2556218343
##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/ConnectionContextProxyTest.java:
##########
@@ -131,15 +145,29 @@ public void testReleaseSavepoint() {
connectionContext.appendUndoItem(new SQLUndoLog());
Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+
+ List<String> expectedKeysList = Arrays.asList("sp1-lock-key",
"sp3-lock-key");
+
+ String actualKeys1 = connectionContext.buildLockKeys();
+ List<String> actualKeysList1 = new
ArrayList<>(Arrays.asList(actualKeys1.split(";")));
+ Collections.sort(actualKeysList1);
+ Assertions.assertEquals(expectedKeysList, actualKeysList1);
connectionContext.releaseSavepoint(sp3);
Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+
+ String actualKeys2 = connectionContext.buildLockKeys();
+ List<String> actualKeysList2 = new
ArrayList<>(Arrays.asList(actualKeys2.split(";")));
+ Collections.sort(actualKeysList2);
+ Assertions.assertEquals(expectedKeysList, actualKeysList2);
connectionContext.releaseSavepoint(null);
Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+
+ String actualKeys3 = connectionContext.buildLockKeys();
+ List<String> actualKeysList3 = new
ArrayList<>(Arrays.asList(actualKeys3.split(";")));
+ Collections.sort(actualKeysList3);
+ Assertions.assertEquals(expectedKeysList, actualKeysList3);
}
Review Comment:
I noticed some code duplication. Would it be possible to extract a common
comparison logic, similar to the following? Of course, the current
implementation is also fine.
```java
private static void assertLockKeysEqual(String actual, String expected) {
if (actual == null && expected == null) {
return;
}
Assertions.assertNotNull(actual, "xxx");
Assertions.assertNotNull(expected, "xxxx");
String[] actualKeys = actual.split(";");
String[] expectedKeys = expected.split(";");
Arrays.sort(actualKeys);
Arrays.sort(expectedKeys);
Assertions.assertArrayEquals(
expectedKeys,
actualKeys,
"xxxxx");
}
@Test
public void testBuildLockKeys() throws Exception {
connectionContext.appendLockKey("abc");
connectionContext.appendLockKey("bcd");
Assertions.assertTrue(connectionContext.hasLockKey());
assertLockKeysEqual(connectionContext.buildLockKeys(), "bcd;abc");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]