diff --git a/core/src/main/java/io/questdb/PropServerConfiguration.java b/core/src/main/java/io/questdb/PropServerConfiguration.java index a68603802eff62c757cf544e6b1ff2e81e757d61..91e07672fe1a7beb6be2984d165c813b142db1d7 100644 --- a/core/src/main/java/io/questdb/PropServerConfiguration.java +++ b/core/src/main/java/io/questdb/PropServerConfiguration.java @@ -35,8 +35,7 @@ import io.questdb.cutlass.http.processors.StaticContentProcessorConfiguration; import io.questdb.cutlass.http.processors.TextImportProcessorConfiguration; import io.questdb.cutlass.json.JsonException; import io.questdb.cutlass.json.JsonLexer; -import io.questdb.cutlass.line.LineProtoNanosTimestampAdapter; -import io.questdb.cutlass.line.LineProtoTimestampAdapter; +import io.questdb.cutlass.line.*; import io.questdb.cutlass.line.udp.LineUdpReceiverConfiguration; import io.questdb.cutlass.pgwire.DefaultPGWireConfiguration; import io.questdb.cutlass.pgwire.PGWireConfiguration; @@ -124,6 +123,7 @@ public class PropServerConfiguration implements ServerConfiguration { } }; private final InputFormatConfiguration inputFormatConfiguration; + private final LineProtoTimestampAdapter lineUdpTimestampAdapter; private boolean httpAllowDeflateBeforeSend; private int[] httpWorkerAffinity; private int connectionPoolInitialCapacity; @@ -336,10 +336,31 @@ public class PropServerConfiguration implements ServerConfiguration { this.lineUdpMsgCount = getInt(properties, "line.udp.msg.count", 10_000); this.lineUdpReceiveBufferSize = getIntSize(properties, "line.udp.receive.buffer.size", 1024 * 1024); this.lineUdpEnabled = getBoolean(properties, "line.udp.enabled", true); -// this.lineUdpWorkerCount = getInt(properties, "line.udp.worker.count", 0); this.lineUdpOwnThreadAffinity = getInt(properties, "line.udp.own.thread.affinity", -1); this.lineUdpOwnThread = getBoolean(properties, "line.udp.own.thread", false); this.lineUdpUnicast = getBoolean(properties, "line.udp.unicast", false); + + final String lineUdpTimestampSwitch = getString(properties, "line.udp.timestamp", "n"); + switch (lineUdpTimestampSwitch) { + case "u": + lineUdpTimestampAdapter = LineProtoMicroTimestampAdapter.INSTANCE; + break; + case "ms": + lineUdpTimestampAdapter = LineProtoMilliTimestampAdapter.INSTANCE; + break; + case "s": + lineUdpTimestampAdapter = LineProtoSecondTimestampAdapter.INSTANCE; + break; + case "m": + lineUdpTimestampAdapter = LineProtoMinuteTimestampAdapter.INSTANCE; + break; + case "h": + lineUdpTimestampAdapter = LineProtoHourTimestampAdapter.INSTANCE; + break; + default: + lineUdpTimestampAdapter = LineProtoNanoTimestampAdapter.INSTANCE; + break; + } } @Override @@ -1114,7 +1135,7 @@ public class PropServerConfiguration implements ServerConfiguration { @Override public LineProtoTimestampAdapter getTimestampAdapter() { - return LineProtoNanosTimestampAdapter.INSTANCE; + return lineUdpTimestampAdapter; } } diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..ae533a1ebb11cc1947e4a62720a925fbcbbe9ba5 --- /dev/null +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapter.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.Numbers; +import io.questdb.std.NumericException; +import io.questdb.std.microtime.Timestamps; + +public class LineProtoHourTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoHourTimestampAdapter INSTANCE = new LineProtoHourTimestampAdapter(); + + @Override + public long getMicros(CharSequence value) throws NumericException { + return Numbers.parseLong(value) * Timestamps.HOUR_MICROS; + } +} diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..c860b8645e633ce16b9afa60acbc603f21363c1c --- /dev/null +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapter.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.Numbers; +import io.questdb.std.NumericException; + +public class LineProtoMicroTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoMicroTimestampAdapter INSTANCE = new LineProtoMicroTimestampAdapter(); + + @Override + public long getMicros(CharSequence value) throws NumericException { + return Numbers.parseLong(value); + } +} diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..88b547eb7f258f132ccea28b9e23aa94a8f24ef2 --- /dev/null +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapter.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.Numbers; +import io.questdb.std.NumericException; + +public class LineProtoMilliTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoMilliTimestampAdapter INSTANCE = new LineProtoMilliTimestampAdapter(); + + @Override + public long getMicros(CharSequence value) throws NumericException { + return Numbers.parseLong(value) * 1000L; + } +} diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..0566938083c91996f77f54d1fb3fc9a92dfdfde4 --- /dev/null +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapter.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.Numbers; +import io.questdb.std.NumericException; +import io.questdb.std.microtime.Timestamps; + +public class LineProtoMinuteTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoMinuteTimestampAdapter INSTANCE = new LineProtoMinuteTimestampAdapter(); + + @Override + public long getMicros(CharSequence value) throws NumericException { + return Numbers.parseLong(value) * Timestamps.MINUTE_MICROS; + } +} diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoNanosTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapter.java similarity index 87% rename from core/src/main/java/io/questdb/cutlass/line/LineProtoNanosTimestampAdapter.java rename to core/src/main/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapter.java index fa6c7478714812c2c7e0abc71099191f548a64fe..43b55c13e1a73975cfe49d1b5217299ae587c0e0 100644 --- a/core/src/main/java/io/questdb/cutlass/line/LineProtoNanosTimestampAdapter.java +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapter.java @@ -27,8 +27,8 @@ package io.questdb.cutlass.line; import io.questdb.std.Numbers; import io.questdb.std.NumericException; -public class LineProtoNanosTimestampAdapter implements LineProtoTimestampAdapter { - public static final LineProtoNanosTimestampAdapter INSTANCE = new LineProtoNanosTimestampAdapter(); +public class LineProtoNanoTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoNanoTimestampAdapter INSTANCE = new LineProtoNanoTimestampAdapter(); @Override public long getMicros(CharSequence value) throws NumericException { diff --git a/core/src/main/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapter.java b/core/src/main/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..19927b7a4b133c5d6a13d5a748711647cf157ce5 --- /dev/null +++ b/core/src/main/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapter.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.Numbers; +import io.questdb.std.NumericException; +import io.questdb.std.microtime.Timestamps; + +public class LineProtoSecondTimestampAdapter implements LineProtoTimestampAdapter { + public static final LineProtoSecondTimestampAdapter INSTANCE = new LineProtoSecondTimestampAdapter(); + + @Override + public long getMicros(CharSequence value) throws NumericException { + return Numbers.parseLong(value) * Timestamps.SECOND_MICROS; + } +} diff --git a/core/src/test/java/io/questdb/PropServerConfigurationTest.java b/core/src/test/java/io/questdb/PropServerConfigurationTest.java index d1e8f5938080f63ed76d39f78699ef4c6f7cabb9..dd2a1a98b2cd4fa92450fb7bf5d88b4daa6d32c8 100644 --- a/core/src/test/java/io/questdb/PropServerConfigurationTest.java +++ b/core/src/test/java/io/questdb/PropServerConfigurationTest.java @@ -27,6 +27,7 @@ package io.questdb; import io.questdb.cairo.CommitMode; import io.questdb.cairo.security.AllowAllCairoSecurityContext; import io.questdb.cutlass.json.JsonException; +import io.questdb.cutlass.line.*; import io.questdb.network.EpollFacadeImpl; import io.questdb.network.IOOperation; import io.questdb.network.NetworkFacadeImpl; @@ -226,6 +227,39 @@ public class PropServerConfigurationTest { new PropServerConfiguration("root", properties); } + @Test + public void testLineUdpTimestamp() throws ServerConfigurationException, JsonException { + Properties properties = new Properties(); + properties.setProperty("http.enabled", "false"); + properties.setProperty("line.udp.timestamp", ""); + PropServerConfiguration configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoNanoTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "n"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoNanoTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "u"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoMicroTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "ms"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoMilliTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "s"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoSecondTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "m"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoMinuteTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + + properties.setProperty("line.udp.timestamp", "h"); + configuration = new PropServerConfiguration("root", properties); + Assert.assertSame(LineProtoHourTimestampAdapter.INSTANCE, configuration.getLineUdpReceiverConfiguration().getTimestampAdapter()); + } + @Test(expected = ServerConfigurationException.class) public void testInvalidBindToPort() throws ServerConfigurationException, JsonException { Properties properties = new Properties(); diff --git a/core/src/test/java/io/questdb/cutlass/line/CairoLineProtoParserTest.java b/core/src/test/java/io/questdb/cutlass/line/CairoLineProtoParserTest.java index 68ec42dcbdc973707b7ca03f3000426b907fbfff..0780bbb100e9c1c7ffc45541056cfd944fdd9505 100644 --- a/core/src/test/java/io/questdb/cutlass/line/CairoLineProtoParserTest.java +++ b/core/src/test/java/io/questdb/cutlass/line/CairoLineProtoParserTest.java @@ -535,7 +535,7 @@ public class CairoLineProtoParserTest extends AbstractCairoTest { private void assertThat(String expected, String lines, CharSequence tableName, CairoConfiguration configuration) throws Exception { TestUtils.assertMemoryLeak(() -> { try (CairoEngine engine = new CairoEngine(configuration, null)) { - try (CairoLineProtoParser parser = new CairoLineProtoParser(engine, AllowAllCairoSecurityContext.INSTANCE, LineProtoNanosTimestampAdapter.INSTANCE)) { + try (CairoLineProtoParser parser = new CairoLineProtoParser(engine, AllowAllCairoSecurityContext.INSTANCE, LineProtoNanoTimestampAdapter.INSTANCE)) { byte[] bytes = lines.getBytes(StandardCharsets.UTF_8); int len = bytes.length; long mem = Unsafe.malloc(len); diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d73c8d53dcadc008a5cfe222d3473a8fdf05b62b --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoHourTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoHourTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(20444400000000L, LineProtoHourTimestampAdapter.INSTANCE.getMicros("5679")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d1a11d8fb25d63cd69b0b63f62fdc7309658e189 --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoMicroTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoMicroTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(5679L, LineProtoMicroTimestampAdapter.INSTANCE.getMicros("5679")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c765d769cdbcd474d9272172617edd9518af1f74 --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoMilliTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoMilliTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(5679000L, LineProtoMilliTimestampAdapter.INSTANCE.getMicros("5679")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..655722e9962fe6bb13cb29ec1f392fffb4c0e050 --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoMinuteTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoMinuteTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(340740000000L, LineProtoMinuteTimestampAdapter.INSTANCE.getMicros("5679")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d228336e44c6053de4118b3e5630bdfaf49b5178 --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoNanoTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoNanoTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(56799L, LineProtoNanoTimestampAdapter.INSTANCE.getMicros("56799000")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapterTest.java b/core/src/test/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5dc89ce67b68ef00d374b45075d191e5e3a46460 --- /dev/null +++ b/core/src/test/java/io/questdb/cutlass/line/LineProtoSecondTimestampAdapterTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ___ _ ____ ____ + * / _ \ _ _ ___ ___| |_| _ \| __ ) + * | | | | | | |/ _ \/ __| __| | | | _ \ + * | |_| | |_| | __/\__ \ |_| |_| | |_) | + * \__\_\\__,_|\___||___/\__|____/|____/ + * + * Copyright (c) 2014-2019 Appsicle + * Copyright (c) 2019-2020 QuestDB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +package io.questdb.cutlass.line; + +import io.questdb.std.NumericException; +import org.junit.Assert; +import org.junit.Test; + +public class LineProtoSecondTimestampAdapterTest { + + @Test + public void testRounding() throws NumericException { + Assert.assertEquals(5679000000L, LineProtoSecondTimestampAdapter.INSTANCE.getMicros("5679")); + } +} \ No newline at end of file diff --git a/core/src/test/java/io/questdb/cutlass/line/udp/LinuxLineProtoReceiverTest.java b/core/src/test/java/io/questdb/cutlass/line/udp/LinuxLineProtoReceiverTest.java index 3b2586f819503ad4f5af559a693cd23c0be800e0..14b3a388cf4e1e0931d9b57db591215d1ae1dfa3 100644 --- a/core/src/test/java/io/questdb/cutlass/line/udp/LinuxLineProtoReceiverTest.java +++ b/core/src/test/java/io/questdb/cutlass/line/udp/LinuxLineProtoReceiverTest.java @@ -27,7 +27,7 @@ package io.questdb.cutlass.line.udp; import io.questdb.WorkerPoolAwareConfiguration; import io.questdb.cairo.*; import io.questdb.cairo.security.AllowAllCairoSecurityContext; -import io.questdb.cutlass.line.LineProtoNanosTimestampAdapter; +import io.questdb.cutlass.line.LineProtoNanoTimestampAdapter; import io.questdb.cutlass.line.LineProtoTimestampAdapter; import io.questdb.network.Net; import io.questdb.network.NetworkFacade; @@ -333,7 +333,7 @@ public class LinuxLineProtoReceiverTest extends AbstractCairoTest { @Override public LineProtoTimestampAdapter getTimestampAdapter() { - return LineProtoNanosTimestampAdapter.INSTANCE; + return LineProtoNanoTimestampAdapter.INSTANCE; } @Override