Skip to content

Commit 0cee86f

Browse files
committed
add tests for sender behavior with omitted columns and packet limits
1 parent a32a771 commit 0cee86f

2 files changed

Lines changed: 110 additions & 1 deletion

File tree

core/src/test/java/io/questdb/client/test/cutlass/qwp/client/QwpUdpSenderTest.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,74 @@ public void testBoundedSenderMixedNullablePaddingPreservesRowsAndPacketLimit() t
136136
});
137137
}
138138

139+
@Test
140+
public void testUnboundedSenderOmittedNullableAndNonNullableColumnsPreservesRows() throws Exception {
141+
assertMemoryLeak(() -> {
142+
List<ScenarioRow> rows = Arrays.asList(
143+
row("t", sender -> sender.table("t")
144+
.longColumn("x", 1)
145+
.stringColumn("s", "alpha")
146+
.symbol("sym", "one")
147+
.atNow(),
148+
"x", 1L,
149+
"s", "alpha",
150+
"sym", "one"),
151+
row("t", sender -> sender.table("t")
152+
.stringColumn("s", "beta")
153+
.atNow(),
154+
"x", Long.MIN_VALUE,
155+
"s", "beta",
156+
"sym", null),
157+
row("t", sender -> sender.table("t")
158+
.longColumn("x", 3)
159+
.atNow(),
160+
"x", 3L,
161+
"s", null,
162+
"sym", null)
163+
);
164+
165+
RunResult result = runScenario(rows, 0);
166+
167+
Assert.assertEquals(1, result.sendCount);
168+
assertRowsEqual(expectedRows(rows), decodeRows(result.packets));
169+
});
170+
}
171+
172+
@Test
173+
public void testBoundedSenderOmittedNonNullableColumnsPreservesRowsAndPacketLimit() throws Exception {
174+
assertMemoryLeak(() -> {
175+
String alpha = repeat('a', 256);
176+
String beta = repeat('b', 192);
177+
String omega = repeat('z', 256);
178+
List<ScenarioRow> rows = Arrays.asList(
179+
row("mix", sender -> sender.table("mix")
180+
.longColumn("x", 1)
181+
.stringColumn("msg", alpha)
182+
.atNow(),
183+
"x", 1L,
184+
"msg", alpha),
185+
row("mix", sender -> sender.table("mix")
186+
.stringColumn("msg", beta)
187+
.atNow(),
188+
"x", Long.MIN_VALUE,
189+
"msg", beta),
190+
row("mix", sender -> sender.table("mix")
191+
.longColumn("x", 3)
192+
.stringColumn("msg", omega)
193+
.atNow(),
194+
"x", 3L,
195+
"msg", omega)
196+
);
197+
198+
int maxDatagramSize = fullPacketSize(rows) - 1;
199+
RunResult result = runScenario(rows, maxDatagramSize);
200+
201+
Assert.assertTrue("expected at least one auto-flush", result.packets.size() > 1);
202+
assertPacketsWithinLimit(result, maxDatagramSize);
203+
assertRowsEqual(expectedRows(rows), decodeRows(result.packets));
204+
});
205+
}
206+
139207
@Test
140208
public void testBoundedSenderArrayReplayPreservesRowsAndPacketLimit() throws Exception {
141209
assertMemoryLeak(() -> {
@@ -552,6 +620,40 @@ public void testSchemaChangeAfterOutOfOrderExistingColumnsPreservesRows() throws
552620
});
553621
}
554622

623+
@Test
624+
public void testBoundedSenderSchemaFlushThenOmittedNullableColumnsPreservesRows() throws Exception {
625+
assertMemoryLeak(() -> {
626+
List<ScenarioRow> rows = Arrays.asList(
627+
row("schema", sender -> sender.table("schema")
628+
.longColumn("x", 1)
629+
.stringColumn("s", "alpha")
630+
.atNow(),
631+
"x", 1L,
632+
"s", "alpha"),
633+
row("schema", sender -> sender.table("schema")
634+
.symbol("sym", "new")
635+
.longColumn("x", 2)
636+
.stringColumn("s", "beta")
637+
.atNow(),
638+
"sym", "new",
639+
"x", 2L,
640+
"s", "beta"),
641+
row("schema", sender -> sender.table("schema")
642+
.longColumn("x", 3)
643+
.atNow(),
644+
"sym", null,
645+
"x", 3L,
646+
"s", null)
647+
);
648+
649+
RunResult result = runScenario(rows, 1024 * 1024);
650+
651+
Assert.assertEquals(2, result.sendCount);
652+
assertPacketsWithinLimit(result, 1024 * 1024);
653+
assertRowsEqual(expectedRows(rows), decodeRows(result.packets));
654+
});
655+
}
656+
555657
@Test
556658
public void testSymbolBoundary16383To16384PreservesRowsAndPacketLimit() throws Exception {
557659
assertMemoryLeak(() -> {

core/src/test/java/io/questdb/client/test/cutlass/qwp/protocol/QwpTableBufferTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.questdb.client.cutlass.line.array.DoubleArray;
2929
import io.questdb.client.cutlass.qwp.protocol.QwpConstants;
3030
import io.questdb.client.cutlass.qwp.protocol.QwpTableBuffer;
31+
import io.questdb.client.std.Unsafe;
3132
import io.questdb.client.std.Decimal128;
3233
import io.questdb.client.std.Decimal64;
3334
import org.junit.Test;
@@ -298,20 +299,26 @@ public void testNextRowWithPreparedMissingColumnsPadsListedColumns() throws Exce
298299
try (QwpTableBuffer table = new QwpTableBuffer("test")) {
299300
QwpTableBuffer.ColumnBuffer colA = table.getOrCreateColumn("a", QwpConstants.TYPE_LONG, false);
300301
QwpTableBuffer.ColumnBuffer colB = table.getOrCreateColumn("b", QwpConstants.TYPE_STRING, true);
302+
QwpTableBuffer.ColumnBuffer colC = table.getOrCreateColumn("c", QwpConstants.TYPE_LONG, false);
301303

302304
colA.addLong(10);
303305
colB.addString("x");
306+
colC.addLong(100);
304307
table.nextRow();
305308

306309
colA.addLong(20);
307-
table.nextRow(new QwpTableBuffer.ColumnBuffer[]{colB}, 1);
310+
table.nextRow(new QwpTableBuffer.ColumnBuffer[]{colB, colC}, 2);
308311

309312
assertEquals(2, colA.getSize());
310313
assertEquals(2, colA.getValueCount());
311314
assertEquals(2, colB.getSize());
312315
assertEquals(1, colB.getValueCount());
313316
assertFalse(colB.isNull(0));
314317
assertTrue(colB.isNull(1));
318+
assertEquals(2, colC.getSize());
319+
assertEquals(2, colC.getValueCount());
320+
assertEquals(100L, Unsafe.getUnsafe().getLong(colC.getDataAddress()));
321+
assertEquals(Long.MIN_VALUE, Unsafe.getUnsafe().getLong(colC.getDataAddress() + Long.BYTES));
315322
}
316323
});
317324
}

0 commit comments

Comments
 (0)