use of io.seata.rm.datasource.undo.BranchUndoLog in project seata by seata.
the class MySQLUndoLogManagerTest method testNeedCompress.
@Test
public void testNeedCompress() throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
SQLUndoLog smallUndoItem = getUndoLogItem(1);
BranchUndoLog smallBranchUndoLog = new BranchUndoLog();
smallBranchUndoLog.setBranchId(1L);
smallBranchUndoLog.setXid("test_xid");
smallBranchUndoLog.setSqlUndoLogs(Collections.singletonList(smallUndoItem));
UndoLogParser parser = UndoLogParserFactory.getInstance();
byte[] smallUndoLogContent = parser.encode(smallBranchUndoLog);
Method method = AbstractUndoLogManager.class.getDeclaredMethod("needCompress", byte[].class);
method.setAccessible(true);
Assertions.assertFalse((Boolean) method.invoke(undoLogManager, smallUndoLogContent));
SQLUndoLog hugeUndoItem = getUndoLogItem(10000);
BranchUndoLog hugeBranchUndoLog = new BranchUndoLog();
hugeBranchUndoLog.setBranchId(2L);
hugeBranchUndoLog.setXid("test_xid1");
hugeBranchUndoLog.setSqlUndoLogs(Collections.singletonList(hugeUndoItem));
byte[] hugeUndoLogContent = parser.encode(hugeBranchUndoLog);
Assertions.assertTrue((Boolean) method.invoke(undoLogManager, hugeUndoLogContent));
}
use of io.seata.rm.datasource.undo.BranchUndoLog in project seata by seata.
the class FastjsonUndoLogParserTest method testWriteClassName.
@Test
public void testWriteClassName() throws Exception {
TableRecords beforeImage = new TableRecords();
TableRecords afterImage = new TableRecords();
afterImage.setTableName("t1");
List<Row> rows = new ArrayList<>();
Row row = new Row();
Field field = new Field();
field.setName("id");
field.setKeyType(KeyType.PRIMARY_KEY);
field.setType(Types.BIGINT);
field.setValue(Long.valueOf("0"));
row.add(field);
field = new Field();
field.setName("money");
field.setType(Types.DECIMAL);
field.setValue(BigDecimal.ONE);
row.add(field);
rows.add(row);
afterImage.setRows(rows);
SQLUndoLog sqlUndoLog00 = new SQLUndoLog();
sqlUndoLog00.setSqlType(SQLType.INSERT);
sqlUndoLog00.setTableName("table_name");
sqlUndoLog00.setBeforeImage(beforeImage);
sqlUndoLog00.setAfterImage(afterImage);
BranchUndoLog originLog = new BranchUndoLog();
originLog.setBranchId(123456L);
originLog.setXid("xiddddddddddd");
List<SQLUndoLog> logList = new ArrayList<>();
logList.add(sqlUndoLog00);
originLog.setSqlUndoLogs(logList);
// start test
byte[] bs = getParser().encode(originLog);
String s = new String(bs);
Assertions.assertTrue(s.contains("\"@type\""));
BranchUndoLog decode = getParser().decode(s.getBytes());
Object value1 = decode.getSqlUndoLogs().get(0).getAfterImage().getRows().get(0).getFields().get(0).getValue();
Object value2 = decode.getSqlUndoLogs().get(0).getAfterImage().getRows().get(0).getFields().get(1).getValue();
Assertions.assertTrue(value1 instanceof Long);
Assertions.assertTrue(value2 instanceof BigDecimal);
}
use of io.seata.rm.datasource.undo.BranchUndoLog in project seata by seata.
the class ProtostuffUndoLogParser method decode.
@Override
public BranchUndoLog decode(byte[] bytes) {
if (bytes.length == 0) {
return new BranchUndoLog();
}
BranchUndoLog fooParsed = schema.newMessage();
ProtostuffIOUtil.mergeFrom(bytes, fooParsed, schema);
return fooParsed;
}
Aggregations