Search in sources :

Example 1 with BranchUndoLog

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));
}
Also used : JacksonUndoLogParser(io.seata.rm.datasource.undo.parser.JacksonUndoLogParser) UndoLogParser(io.seata.rm.datasource.undo.UndoLogParser) BranchUndoLog(io.seata.rm.datasource.undo.BranchUndoLog) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 2 with BranchUndoLog

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);
}
Also used : ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) TableRecords(io.seata.rm.datasource.sql.struct.TableRecords) Field(io.seata.rm.datasource.sql.struct.Field) BranchUndoLog(io.seata.rm.datasource.undo.BranchUndoLog) SQLUndoLog(io.seata.rm.datasource.undo.SQLUndoLog) Row(io.seata.rm.datasource.sql.struct.Row) Test(org.junit.jupiter.api.Test) BaseUndoLogParserTest(io.seata.rm.datasource.undo.BaseUndoLogParserTest)

Example 3 with BranchUndoLog

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;
}
Also used : BranchUndoLog(io.seata.rm.datasource.undo.BranchUndoLog)

Aggregations

BranchUndoLog (io.seata.rm.datasource.undo.BranchUndoLog)3 SQLUndoLog (io.seata.rm.datasource.undo.SQLUndoLog)2 Test (org.junit.jupiter.api.Test)2 Field (io.seata.rm.datasource.sql.struct.Field)1 Row (io.seata.rm.datasource.sql.struct.Row)1 TableRecords (io.seata.rm.datasource.sql.struct.TableRecords)1 BaseUndoLogParserTest (io.seata.rm.datasource.undo.BaseUndoLogParserTest)1 UndoLogParser (io.seata.rm.datasource.undo.UndoLogParser)1 JacksonUndoLogParser (io.seata.rm.datasource.undo.parser.JacksonUndoLogParser)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1