use of io.seata.server.storage.file.session.FileSessionManager in project seata by seata.
the class FileTransactionStoreManagerTest method testFindTimeoutAndSave.
@Test
public void testFindTimeoutAndSave() throws Exception {
File seataFile = Files.newTemporaryFile();
Method findTimeoutAndSaveMethod = FileTransactionStoreManager.class.getDeclaredMethod("findTimeoutAndSave");
findTimeoutAndSaveMethod.setAccessible(true);
FileSessionManager sessionManager = null;
FileTransactionStoreManager fileTransactionStoreManager = null;
try {
List<GlobalSession> timeoutSessions = new ArrayList<>();
for (int i = 0; i < 100; i++) {
GlobalSession globalSession = new GlobalSession("", "", "", 60000);
BranchSession branchSessionA = Mockito.mock(BranchSession.class);
Mockito.when(branchSessionA.encode()).thenReturn(createBigBranchSessionData(globalSession, (byte) 'A'));
Mockito.when(branchSessionA.getApplicationData()).thenReturn(new String(createBigApplicationData((byte) 'A')));
globalSession.addBranch(branchSessionA);
BranchSession branchSessionB = Mockito.mock(BranchSession.class);
Mockito.when(branchSessionB.encode()).thenReturn(createBigBranchSessionData(globalSession, (byte) 'B'));
Mockito.when(branchSessionB.getApplicationData()).thenReturn(new String(createBigApplicationData((byte) 'B')));
globalSession.addBranch(branchSessionB);
timeoutSessions.add(globalSession);
}
SessionManager sessionManagerMock = Mockito.mock(SessionManager.class);
Mockito.when(sessionManagerMock.findGlobalSessions(Mockito.any())).thenReturn(timeoutSessions);
fileTransactionStoreManager = new FileTransactionStoreManager(seataFile.getAbsolutePath(), sessionManagerMock);
Assertions.assertTrue((boolean) findTimeoutAndSaveMethod.invoke(fileTransactionStoreManager));
sessionManager = new FileSessionManager(seataFile.getName(), seataFile.getParent());
sessionManager.reload();
Collection<GlobalSession> globalSessions = sessionManager.allSessions();
Assertions.assertNotNull(globalSessions);
globalSessions.forEach(g -> {
Assertions.assertNotNull(g);
List<BranchSession> branches = g.getBranchSessions();
Assertions.assertEquals(2, branches.size());
Assertions.assertEquals(new String(createBigApplicationData((byte) 'A')), branches.get(0).getApplicationData());
Assertions.assertEquals(new String(createBigApplicationData((byte) 'B')), branches.get(1).getApplicationData());
});
} finally {
findTimeoutAndSaveMethod.setAccessible(false);
if (fileTransactionStoreManager != null) {
fileTransactionStoreManager.shutdown();
}
if (sessionManager != null) {
sessionManager.destroy();
}
Assertions.assertTrue(seataFile.delete());
}
}
use of io.seata.server.storage.file.session.FileSessionManager in project seata by seata.
the class GlobalSessionTest method globalSessionProvider.
/**
* Global session provider object [ ] [ ].
*
* @return the object [ ] [ ]
*/
static Stream<Arguments> globalSessionProvider() throws IOException {
GlobalSession globalSession = new GlobalSession("demo-app", "my_test_tx_group", "test", 6000);
globalSession.setActive(true);
globalSession.addSessionLifecycleListener(new FileSessionManager("default", null));
return Stream.of(Arguments.of(globalSession));
}
Aggregations