|
29 | 29 | import io.questdb.ServerMain; |
30 | 30 | import io.questdb.cairo.CairoEngine; |
31 | 31 | import io.questdb.cairo.ColumnType; |
| 32 | +import io.questdb.cairo.DefaultDdlListener; |
32 | 33 | import io.questdb.cairo.MicrosTimestampDriver; |
33 | 34 | import io.questdb.cairo.NanosTimestampDriver; |
| 35 | +import io.questdb.cairo.SecurityContext; |
34 | 36 | import io.questdb.cairo.TableToken; |
35 | 37 | import io.questdb.cairo.sql.TableMetadata; |
36 | 38 | import io.questdb.client.Sender; |
|
62 | 64 | import java.lang.reflect.Array; |
63 | 65 | import java.time.Instant; |
64 | 66 | import java.time.temporal.ChronoUnit; |
| 67 | +import java.util.concurrent.atomic.AtomicBoolean; |
65 | 68 |
|
66 | 69 | import static io.questdb.PropertyKey.DEBUG_FORCE_RECV_FRAGMENTATION_CHUNK_SIZE; |
67 | 70 | import static io.questdb.PropertyKey.LINE_HTTP_ENABLED; |
@@ -874,6 +877,50 @@ public void testCreateTimestampColumnsWithDesignatedNanosV2() throws Exception { |
874 | 877 | "1.111\t2025-11-19T10:55:24.123456789Z\t2025-11-19T10:55:24.123456Z\t2025-11-19T10:55:24.123000Z\t2025-11-19T10:55:24.123456799Z\t2025-11-20T10:55:24.123456789Z"); |
875 | 878 | } |
876 | 879 |
|
| 880 | + @Test |
| 881 | + public void testDdlListenerOnTableCreated() throws Exception { |
| 882 | + TestUtils.assertMemoryLeak(() -> { |
| 883 | + try (final TestServerMain questdb = startWithEnvVariables()) { |
| 884 | + final AtomicBoolean failed = new AtomicBoolean(); |
| 885 | + final CairoEngine engine = questdb.getEngine(); |
| 886 | + engine.setDdlListener(new DefaultDdlListener() { |
| 887 | + @Override |
| 888 | + public void onTableOrMatViewCreated(SecurityContext securityContext, TableToken tableToken, int tableKind) { |
| 889 | + try { |
| 890 | + // assert that this is the expected table name and id |
| 891 | + final int tableId = (int) engine.getTableIdGenerator().getCurrentId(); |
| 892 | + Assert.assertEquals("tab", tableToken.getTableName()); |
| 893 | + Assert.assertEquals(tableId, tableToken.getTableId()); |
| 894 | + |
| 895 | + // assert that the table is not available to others for reading yet |
| 896 | + Assert.assertNull(engine.getTableTokenIfExists("tab")); |
| 897 | + |
| 898 | + // assert that others competing to create the same table, cannot lock the table name |
| 899 | + Assert.assertNull(engine.lockTableName("tab", tableId, false, true)); |
| 900 | + } catch (Throwable th) { |
| 901 | + th.printStackTrace(System.out); |
| 902 | + failed.set(true); |
| 903 | + } |
| 904 | + } |
| 905 | + }); |
| 906 | + |
| 907 | + try (Sender sender = Sender.builder(Sender.Transport.HTTP) |
| 908 | + .address("localhost:" + questdb.getHttpServerPort()) |
| 909 | + .build() |
| 910 | + ) { |
| 911 | + sender.table("tab").longColumn("col", 1).atNow(); |
| 912 | + } catch (Throwable e) { |
| 913 | + e.printStackTrace(System.out); |
| 914 | + Assert.fail("Failed to ingest data, check log for exception"); |
| 915 | + } |
| 916 | + |
| 917 | + if (failed.get()) { |
| 918 | + Assert.fail("Failed in DDL listener, check log for exception"); |
| 919 | + } |
| 920 | + } |
| 921 | + }); |
| 922 | + } |
| 923 | + |
877 | 924 | @Test |
878 | 925 | public void testEmptyArraysMultiDimensional() throws Exception { |
879 | 926 | TestUtils.assertMemoryLeak(() -> { |
|
0 commit comments