From bc20153815289dfd1f19907ea1a7aa4c3c3f297f Mon Sep 17 00:00:00 2001 From: luometeor <916699863@qq.com> Date: Tue, 19 Sep 2023 21:42:52 +0800 Subject: [PATCH] feature: fix test --- .../server/coordinator/DefaultCoordinatorTest.java | 8 +++++--- .../store/file/FileTransactionStoreManagerTest.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java b/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java index 1890423683d..b3cd249afd0 100644 --- a/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java +++ b/server/src/test/java/io/seata/server/coordinator/DefaultCoordinatorTest.java @@ -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); } @@ -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 { @@ -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(); diff --git a/server/src/test/java/io/seata/server/store/file/FileTransactionStoreManagerTest.java b/server/src/test/java/io/seata/server/store/file/FileTransactionStoreManagerTest.java index f311482d455..a89d33459df 100644 --- a/server/src/test/java/io/seata/server/store/file/FileTransactionStoreManagerTest.java +++ b/server/src/test/java/io/seata/server/store/file/FileTransactionStoreManagerTest.java @@ -60,15 +60,18 @@ 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 list = fileTransactionStoreManager.readWriteStore(2000, false); @@ -76,8 +79,10 @@ public void testBigDataWrite() throws Exception { 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(); @@ -97,6 +102,7 @@ public void testFindTimeoutAndSave() throws Exception { List 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')); @@ -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; @@ -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);