|
31 | 31 | import org.apache.iotdb.confignode.manager.ConfigManager; |
32 | 32 | import org.apache.iotdb.confignode.manager.TTLManager; |
33 | 33 | import org.apache.iotdb.confignode.manager.node.NodeManager; |
| 34 | +import org.apache.iotdb.confignode.procedure.Procedure; |
34 | 35 | import org.apache.iotdb.confignode.procedure.env.ConfigNodeProcedureEnv; |
| 36 | +import org.apache.iotdb.confignode.procedure.state.ProcedureState; |
35 | 37 | import org.apache.iotdb.confignode.procedure.state.schema.SetTTLState; |
36 | 38 | import org.apache.iotdb.confignode.procedure.store.ProcedureFactory; |
| 39 | +import org.apache.iotdb.confignode.procedure.store.ProcedureType; |
37 | 40 | import org.apache.iotdb.rpc.TSStatusCode; |
38 | 41 |
|
39 | 42 | import org.apache.tsfile.utils.PublicBAOS; |
| 43 | +import org.apache.tsfile.utils.ReadWriteIOUtils; |
40 | 44 | import org.junit.Assert; |
41 | 45 | import org.junit.Test; |
42 | 46 | import org.mockito.Mockito; |
@@ -111,6 +115,25 @@ public void serializeDeserializeTestWithCapturedRollbackState() throws Exception |
111 | 115 | deserializedProcedure, "root.db", 2000L, true, true, 500L, 600L, false); |
112 | 116 | } |
113 | 117 |
|
| 118 | + @Test |
| 119 | + public void deserializeOldFormatWithoutRollbackStateTest() throws Exception { |
| 120 | + final SetTTLPlan setTTLPlan = |
| 121 | + new SetTTLPlan(Arrays.asList(new PartialPath("root.db").getNodes()), 2000L); |
| 122 | + setTTLPlan.setDataBase(true); |
| 123 | + |
| 124 | + final PublicBAOS byteArrayOutputStream = new PublicBAOS(); |
| 125 | + final DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream); |
| 126 | + writeOldFormatProcedure(outputStream, setTTLPlan); |
| 127 | + |
| 128 | + final ByteBuffer buffer = |
| 129 | + ByteBuffer.wrap(byteArrayOutputStream.getBuf(), 0, byteArrayOutputStream.size()); |
| 130 | + final SetTTLProcedure deserializedProcedure = |
| 131 | + (SetTTLProcedure) ProcedureFactory.getInstance().create(buffer); |
| 132 | + |
| 133 | + assertSerializedProcedure( |
| 134 | + deserializedProcedure, "root.db", 2000L, true, false, Long.MIN_VALUE, Long.MIN_VALUE, false); |
| 135 | + } |
| 136 | + |
114 | 137 | @Test |
115 | 138 | public void setConfigNodeTTLShouldNotWriteBeforePreviousStateIsCaptured() throws Exception { |
116 | 139 | final SetTTLPlan setTTLPlan = |
@@ -229,6 +252,25 @@ private void assertRequest( |
229 | 252 | Assert.assertEquals(isDataBase, req.isDataBase); |
230 | 253 | } |
231 | 254 |
|
| 255 | + private void writeOldFormatProcedure(final DataOutputStream stream, final SetTTLPlan plan) |
| 256 | + throws IOException { |
| 257 | + stream.writeShort(ProcedureType.SET_TTL_PROCEDURE.getTypeCode()); |
| 258 | + // Procedure fields. |
| 259 | + stream.writeLong(Procedure.NO_PROC_ID); |
| 260 | + stream.writeInt(ProcedureState.INITIALIZING.ordinal()); |
| 261 | + stream.writeLong(0L); |
| 262 | + stream.writeLong(0L); |
| 263 | + stream.writeLong(Procedure.NO_PROC_ID); |
| 264 | + stream.writeLong(Procedure.NO_TIMEOUT); |
| 265 | + stream.writeInt(-1); // no stack indexes |
| 266 | + stream.write((byte) 0); // no exception |
| 267 | + stream.writeInt(-1); // no result |
| 268 | + stream.write((byte) 0); // no lock |
| 269 | + // StateMachineProcedure fields. |
| 270 | + stream.writeInt(0); // no states |
| 271 | + ReadWriteIOUtils.write(plan.serializeToByteBuffer(), stream); |
| 272 | + } |
| 273 | + |
232 | 274 | private void assertSerializedProcedure( |
233 | 275 | final SetTTLProcedure procedure, |
234 | 276 | final String path, |
|
0 commit comments