Skip to content

Commit

Permalink
feature: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MeteorShower-l committed Sep 19, 2023
1 parent 836f785 commit bc20153
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ public void test_handleRetryRollbacking() throws TransactionException, Interrupt
Long branchId = core.branchRegister(BranchType.AT, "abcd", clientId, xid, applicationData, lockKeys_2);

Assertions.assertNotNull(branchId);

GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
Thread.sleep(100);
defaultCoordinator.timeoutCheck();
TimeUnit.MILLISECONDS.sleep(globalSession.getGmtModified() - globalSession.getBeginTime());
defaultCoordinator.handleRetryRollbacking();

GlobalSession globalSession = SessionHolder.findGlobalSession(xid);
globalSession = SessionHolder.findGlobalSession(xid);
Assertions.assertNull(globalSession);

}
Expand All @@ -173,6 +174,7 @@ public void test_handleRetryRollbackingTimeOut() throws TransactionException, In
ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE", false);
TimeUnit.MILLISECONDS.sleep(100);
globalSession.queueToRetryRollback();
TimeUnit.MILLISECONDS.sleep(globalSession.getGmtModified() - globalSession.getBeginTime());
defaultCoordinator.handleRetryRollbacking();
int lockSize = globalSession.getBranchSessions().get(0).getLockHolder().size();
try {
Expand All @@ -199,8 +201,8 @@ public void test_handleRetryRollbackingTimeOut_unlock() throws TransactionExcept
ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "MAX_ROLLBACK_RETRY_TIMEOUT", 10L);
ReflectionUtil.modifyStaticFinalField(defaultCoordinator.getClass(), "ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE", true);
TimeUnit.MILLISECONDS.sleep(100);

globalSession.queueToRetryRollback();
TimeUnit.MILLISECONDS.sleep(globalSession.getGmtModified() - globalSession.getBeginTime());
defaultCoordinator.handleRetryRollbacking();

int lockSize = globalSession.getBranchSessions().get(0).getLockHolder().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,29 @@ public void testBigDataWrite() throws Exception {
fileTransactionStoreManager = new FileTransactionStoreManager(seataFile.getAbsolutePath(), null);
BranchSession branchSessionA = Mockito.mock(BranchSession.class);
GlobalSession global = new GlobalSession();
global.setGmtModified(System.currentTimeMillis());
Mockito.when(branchSessionA.encode())
.thenReturn(createBigBranchSessionData(global, (byte) 'A'));
Mockito.when(branchSessionA.getApplicationData())
.thenReturn(new String(createBigApplicationData((byte) 'A')));
Mockito.when(branchSessionA.getGmtModified()).thenReturn(global.getGmtModified());
BranchSession branchSessionB = Mockito.mock(BranchSession.class);
Mockito.when(branchSessionB.encode())
.thenReturn(createBigBranchSessionData(global, (byte) 'B'));
Mockito.when(branchSessionB.getApplicationData())
.thenReturn(new String(createBigApplicationData((byte) 'B')));
Mockito.when(branchSessionB.getGmtModified()).thenReturn(global.getGmtModified());
Assertions.assertTrue(fileTransactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_ADD, branchSessionA));
Assertions.assertTrue(fileTransactionStoreManager.writeSession(TransactionStoreManager.LogOperation.BRANCH_ADD, branchSessionB));
List<TransactionWriteStore> list = fileTransactionStoreManager.readWriteStore(2000, false);
Assertions.assertNotNull(list);
Assertions.assertEquals(2, list.size());
BranchSession loadedBranchSessionA = (BranchSession) list.get(0).getSessionRequest();
Assertions.assertEquals(branchSessionA.getApplicationData(), loadedBranchSessionA.getApplicationData());
Assertions.assertEquals(branchSessionA.getGmtModified(), loadedBranchSessionA.getGmtModified());
BranchSession loadedBranchSessionB = (BranchSession) list.get(1).getSessionRequest();
Assertions.assertEquals(branchSessionB.getApplicationData(), loadedBranchSessionB.getApplicationData());
Assertions.assertEquals(branchSessionB.getGmtModified(), loadedBranchSessionB.getGmtModified());
} finally {
if (fileTransactionStoreManager != null) {
fileTransactionStoreManager.shutdown();
Expand All @@ -97,6 +102,7 @@ public void testFindTimeoutAndSave() throws Exception {
List<GlobalSession> timeoutSessions = new ArrayList<>();
for (int i = 0; i < 100; i++) {
GlobalSession globalSession = new GlobalSession("", "", "", 60000);
globalSession.setGmtModified(System.currentTimeMillis());
BranchSession branchSessionA = Mockito.mock(BranchSession.class);
Mockito.when(branchSessionA.encode())
.thenReturn(createBigBranchSessionData(globalSession, (byte) 'A'));
Expand Down Expand Up @@ -151,7 +157,7 @@ private byte[] createBigBranchSessionData(GlobalSession global, byte c) {
+ 4 // applicationDataBytes.length
+ 4 // xidBytes.size
+ 1 // statusCode
+ 1 // lockstatus
+ 8 // gmtModified
+ 1; //branchType
String xid = global.getXid();
byte[] xidBytes = null;
Expand All @@ -176,7 +182,7 @@ private byte[] createBigBranchSessionData(GlobalSession global, byte c) {
}
byteBuffer.put((byte) 0);
byteBuffer.put((byte) 0);
byteBuffer.put((byte) 0);
byteBuffer.putLong(global.getGmtModified());
byteBuffer.flip();
byte[] bytes = new byte[byteBuffer.limit()];
byteBuffer.get(bytes);
Expand Down

0 comments on commit bc20153

Please sign in to comment.