Skip to content

Commit 5409c4a

Browse files
committed
Add sort
1 parent 5d21e1e commit 5409c4a

2 files changed

Lines changed: 284 additions & 0 deletions

File tree

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/source/ShowReceiversOperatorTest.java

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,139 @@ public void testSystemUserSeesAllReceiverSnapshots() {
238238
assertFalse(operator.hasNext());
239239
}
240240

241+
@Test
242+
public void testShowReceiversOutputKeepsDefaultSnapshotOrdering() {
243+
registry.registerOrUpdateSession(
244+
"data-user-b",
245+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
246+
1,
247+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
248+
"10.0.0.2",
249+
9006,
250+
"bob",
251+
"cluster-a",
252+
"pipe-f",
253+
6,
254+
600);
255+
registry.registerOrUpdateSession(
256+
"data-address-a",
257+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
258+
1,
259+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
260+
"10.0.0.1",
261+
9004,
262+
"root",
263+
"cluster-a",
264+
"pipe-d",
265+
4,
266+
400);
267+
registry.registerOrUpdateSession(
268+
"config-node-2",
269+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
270+
2,
271+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
272+
"10.0.0.1",
273+
9002,
274+
"root",
275+
"cluster-a",
276+
"pipe-b",
277+
2,
278+
200);
279+
registry.registerOrUpdateSession(
280+
"data-user-a",
281+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
282+
1,
283+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
284+
"10.0.0.2",
285+
9005,
286+
"alice",
287+
"cluster-a",
288+
"pipe-e",
289+
5,
290+
500);
291+
registry.registerOrUpdateSession(
292+
"config-node-1",
293+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
294+
1,
295+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
296+
"10.0.0.1",
297+
9001,
298+
"root",
299+
"cluster-a",
300+
"pipe-a",
301+
1,
302+
100);
303+
registry.registerOrUpdateSession(
304+
"data-air-gap",
305+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
306+
1,
307+
PipeReceiverRuntimeRegistry.PROTOCOL_AIR_GAP,
308+
"10.0.0.2",
309+
9003,
310+
"root",
311+
"cluster-a",
312+
"pipe-c",
313+
3,
314+
300);
315+
316+
final ShowReceiversOperator operator =
317+
new ShowReceiversOperator(null, new PlanNodeId("show-receivers"));
318+
319+
assertTrue(operator.hasNext());
320+
final TsBlock tsBlock = operator.next();
321+
322+
assertEquals(6, tsBlock.getPositionCount());
323+
assertRowKey(
324+
tsBlock,
325+
0,
326+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
327+
1,
328+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
329+
"10.0.0.1",
330+
"root");
331+
assertRowKey(
332+
tsBlock,
333+
1,
334+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
335+
2,
336+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
337+
"10.0.0.1",
338+
"root");
339+
assertRowKey(
340+
tsBlock,
341+
2,
342+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
343+
1,
344+
PipeReceiverRuntimeRegistry.PROTOCOL_AIR_GAP,
345+
"10.0.0.2",
346+
"root");
347+
assertRowKey(
348+
tsBlock,
349+
3,
350+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
351+
1,
352+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
353+
"10.0.0.1",
354+
"root");
355+
assertRowKey(
356+
tsBlock,
357+
4,
358+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
359+
1,
360+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
361+
"10.0.0.2",
362+
"alice");
363+
assertRowKey(
364+
tsBlock,
365+
5,
366+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
367+
1,
368+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
369+
"10.0.0.2",
370+
"bob");
371+
assertFalse(operator.hasNext());
372+
}
373+
241374
private void registerUserSession(
242375
String connectionKey,
243376
String senderAddress,
@@ -268,4 +401,19 @@ private static String getText(final TsBlock tsBlock, final int columnIndex) {
268401
private static String getText(final TsBlock tsBlock, final int columnIndex, final int position) {
269402
return tsBlock.getColumn(columnIndex).getBinary(position).toString();
270403
}
404+
405+
private static void assertRowKey(
406+
final TsBlock tsBlock,
407+
final int position,
408+
final String receiverNodeType,
409+
final int receiverNodeId,
410+
final String protocol,
411+
final String senderAddress,
412+
final String userName) {
413+
assertEquals(receiverNodeType, getText(tsBlock, 0, position));
414+
assertEquals(receiverNodeId, tsBlock.getColumn(1).getInt(position));
415+
assertEquals(protocol, getText(tsBlock, 2, position));
416+
assertEquals(senderAddress, getText(tsBlock, 3, position));
417+
assertEquals(userName, getText(tsBlock, 8, position));
418+
}
271419
}

iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/pipe/receiver/runtime/PipeReceiverRuntimeRegistryTest.java

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,128 @@ public void testAggregateAndSortSnapshots() {
191191
assertEquals(200, dataSnapshot.getLastTransferTime());
192192
}
193193

194+
@Test
195+
public void testDefaultSnapshotOrderingUsesAllDocumentedKeys() {
196+
registry.registerOrUpdateSession(
197+
"data-user-b",
198+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
199+
1,
200+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
201+
"10.0.0.2",
202+
9006,
203+
"bob",
204+
"cluster-a",
205+
"pipe-f",
206+
6,
207+
600);
208+
registry.registerOrUpdateSession(
209+
"data-address-a",
210+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
211+
1,
212+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
213+
"10.0.0.1",
214+
9004,
215+
"root",
216+
"cluster-a",
217+
"pipe-d",
218+
4,
219+
400);
220+
registry.registerOrUpdateSession(
221+
"config-node-2",
222+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
223+
2,
224+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
225+
"10.0.0.1",
226+
9002,
227+
"root",
228+
"cluster-a",
229+
"pipe-b",
230+
2,
231+
200);
232+
registry.registerOrUpdateSession(
233+
"data-user-a",
234+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
235+
1,
236+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
237+
"10.0.0.2",
238+
9005,
239+
"alice",
240+
"cluster-a",
241+
"pipe-e",
242+
5,
243+
500);
244+
registry.registerOrUpdateSession(
245+
"config-node-1",
246+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
247+
1,
248+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
249+
"10.0.0.1",
250+
9001,
251+
"root",
252+
"cluster-a",
253+
"pipe-a",
254+
1,
255+
100);
256+
registry.registerOrUpdateSession(
257+
"data-air-gap",
258+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
259+
1,
260+
PipeReceiverRuntimeRegistry.PROTOCOL_AIR_GAP,
261+
"10.0.0.2",
262+
9003,
263+
"root",
264+
"cluster-a",
265+
"pipe-c",
266+
3,
267+
300);
268+
269+
final List<PipeReceiverRuntimeSnapshot> snapshots = registry.snapshot();
270+
271+
assertEquals(6, snapshots.size());
272+
assertSnapshotOrderKey(
273+
snapshots.get(0),
274+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
275+
1,
276+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
277+
"10.0.0.1",
278+
"root");
279+
assertSnapshotOrderKey(
280+
snapshots.get(1),
281+
PipeReceiverRuntimeRegistry.NODE_TYPE_CONFIG_NODE,
282+
2,
283+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
284+
"10.0.0.1",
285+
"root");
286+
assertSnapshotOrderKey(
287+
snapshots.get(2),
288+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
289+
1,
290+
PipeReceiverRuntimeRegistry.PROTOCOL_AIR_GAP,
291+
"10.0.0.2",
292+
"root");
293+
assertSnapshotOrderKey(
294+
snapshots.get(3),
295+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
296+
1,
297+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
298+
"10.0.0.1",
299+
"root");
300+
assertSnapshotOrderKey(
301+
snapshots.get(4),
302+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
303+
1,
304+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
305+
"10.0.0.2",
306+
"alice");
307+
assertSnapshotOrderKey(
308+
snapshots.get(5),
309+
PipeReceiverRuntimeRegistry.NODE_TYPE_DATA_NODE,
310+
1,
311+
PipeReceiverRuntimeRegistry.PROTOCOL_THRIFT,
312+
"10.0.0.2",
313+
"bob");
314+
}
315+
194316
@Test
195317
public void testDeregisterSession() {
196318
registry.registerOrUpdateSession(
@@ -693,4 +815,18 @@ private static PipeReceiverRuntimeSnapshot findSnapshot(
693815
}
694816
return null;
695817
}
818+
819+
private static void assertSnapshotOrderKey(
820+
PipeReceiverRuntimeSnapshot snapshot,
821+
String receiverNodeType,
822+
int receiverNodeId,
823+
String protocol,
824+
String senderAddress,
825+
String userName) {
826+
assertEquals(receiverNodeType, snapshot.getReceiverNodeType());
827+
assertEquals(receiverNodeId, snapshot.getReceiverNodeId());
828+
assertEquals(protocol, snapshot.getProtocol());
829+
assertEquals(senderAddress, snapshot.getSenderAddress());
830+
assertEquals(userName, snapshot.getUserName());
831+
}
696832
}

0 commit comments

Comments
 (0)