Skip to content

Commit

Permalink
chore(core): test refactoring (questdb#4230)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluestreak01 authored Feb 25, 2024
1 parent ef33e3f commit 322d412
Show file tree
Hide file tree
Showing 76 changed files with 2,228 additions and 2,302 deletions.
8 changes: 3 additions & 5 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.questdb</groupId>
<artifactId>benchmarks</artifactId>
<version>7.3.10-SNAPSHOT</version>
<version>7.3.11-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JMH benchmarks for QuestDB</name>

Expand Down Expand Up @@ -141,8 +140,7 @@
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
Expand Down
16 changes: 5 additions & 11 deletions compat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>io.questdb</groupId>
<artifactId>compat</artifactId>
<version>7.3.10-SNAPSHOT</version>
<version>7.3.11-SNAPSHOT</version>

<name>Compatibility tests for QuestDB</name>

Expand All @@ -52,19 +52,13 @@
<dependency>
<groupId>org.questdb</groupId>
<artifactId>questdb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.questdb</groupId>
<artifactId>questdb</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.51.v20230217</version>
<version>9.4.54.v20240208</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -76,13 +70,13 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
<version>42.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.23</version>
<version>2.24</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
130 changes: 130 additions & 0 deletions compat/src/test/java/io/questdb/compat/AbstractTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2023 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.compat;

import io.questdb.cairo.CairoEngine;
import io.questdb.griffin.SqlException;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.std.*;
import io.questdb.std.str.Path;
import io.questdb.std.str.StringSink;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

import java.util.concurrent.TimeUnit;

public class AbstractTest {
@ClassRule
public static final TemporaryFolder temp = new TemporaryFolder();
protected static final Log LOG = LogFactory.getLog(AbstractTest.class);
protected static String root;
@Rule
public final TestName testName = new TestName();
protected final StringSink sink = new StringSink();

public static void assertEventually(Runnable assertion) {
assertEventually(assertion, 30);
}

public static void assertEventually(Runnable assertion, int timeoutSeconds) {
long maxSleepingTimeMillis = 1000;
long nextSleepingTimeMillis = 10;
long startTime = System.nanoTime();
long deadline = startTime + TimeUnit.SECONDS.toNanos(timeoutSeconds);
for (; ; ) {
try {
assertion.run();
return;
} catch (AssertionError error) {
if (System.nanoTime() >= deadline) {
throw error;
}
}
Os.sleep(nextSleepingTimeMillis);
nextSleepingTimeMillis = Math.min(maxSleepingTimeMillis, nextSleepingTimeMillis << 1);
}
}

public static void createTestPath() {
final Path path = Path.getThreadLocal(root);
if (Files.exists(path)) {
return;
}
Files.mkdirs(path.of(root).slash$(), 509);
}

public static Rnd generateRandom() {
return generateRandom(null, System.nanoTime(), System.currentTimeMillis());
}

public static Rnd generateRandom(Log log, long s0, long s1) {
if (log != null) {
log.info().$("random seeds: ").$(s0).$("L, ").$(s1).$('L').$();
}
System.out.printf("random seeds: %dL, %dL%n", s0, s1);
return new Rnd(s0, s1);
}

public static void removeTestPath() {
final Path path = Path.getThreadLocal(root);
FilesFacade ff = FilesFacadeImpl.INSTANCE;
path.slash$();
Assert.assertTrue("Test dir cleanup error", !ff.exists(path) || ff.rmdir(path.slash$()));
}

@BeforeClass
public static void setUpStatic() throws Exception {
// it is necessary to initialise logger before tests start
// logger doesn't relinquish memory until JVM stops
// which causes memory leak detector to fail should logger be
// created mid-test
LOG.info().$("setup logger").$();
root = temp.newFolder("dbRoot").getAbsolutePath();
}

@AfterClass
public static void tearDownStatic() {
removeTestPath();
}

public void assertSql(CairoEngine engine, CharSequence sql, CharSequence expectedResult) throws SqlException {
engine.print(sql, sink);
Assert.assertTrue(Chars.equals(sink, expectedResult));
}

@Before
public void setUp() {
LOG.info().$("Starting test ").$(getClass().getSimpleName()).$('#').$(testName.getMethodName()).$();
createTestPath();
}

@After
public void tearDown() {
LOG.info().$("Finished test ").$(getClass().getSimpleName()).$('#').$(testName.getMethodName()).$();
removeTestPath();
}
}
Loading

0 comments on commit 322d412

Please sign in to comment.