| 58 | import java.util.concurrent.atomic.AtomicInteger; |
| 59 | |
| 60 | @SuppressWarnings("ClassEscapesDefinedScope") |
| 61 | @OrderWith(RandomOrder.class) |
| 62 | public class AbstractTest { |
| 63 | public static final Set<QuietCloseable> CLOSEABLE = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
| 64 | |
| 65 | @ClassRule |
| 66 | public static final TemporaryFolder temp = new TemporaryFolder(); |
| 67 | protected static final Log LOG = LogFactory.getLog(AbstractTest.class); |
| 68 | protected static final AtomicInteger OFF_POOL_READER_ID = new AtomicInteger(); |
| 69 | protected static String root; |
| 70 | @Rule |
| 71 | public final TestName testName = new TestName(); |
| 72 | |
| 73 | @BeforeClass |
| 74 | public static void setUpStatic() throws Exception { |
| 75 | TestOs.init(); |
| 76 | Zip.init(); |
| 77 | // it is necessary to initialize logger before tests start |
| 78 | // logger doesn't relinquish memory until JVM stops, |
| 79 | // which causes memory leak detector to fail should logger be |
| 80 | // created mid-test |
| 81 | LOG.info().$("setup logger").$(); |
| 82 | root = temp.newFolder("dbRoot").getAbsolutePath(); |
| 83 | } |
| 84 | |
| 85 | @AfterClass |
| 86 | public static void tearDownStatic() { |
| 87 | TestUtils.removeTestPath(root); |
| 88 | } |
| 89 | |
| 90 | @Before |
| 91 | public void setUp() { |
| 92 | LOG.info().$("Starting test ").$safe(getClass().getSimpleName()).$('#').$safe(testName.getMethodName()).$(); |
| 93 | TestUtils.createTestPath(root); |
| 94 | Metrics.ENABLED.clear(); |
| 95 | SqlCodeGenerator.ALLOW_FUNCTION_MEMOIZATION = false; |
| 96 | } |
| 97 | |
| 98 | @After |
| 99 | public void tearDown() throws Exception { |
| 100 | LOG.info().$("Finished test ").$safe(getClass().getSimpleName()).$('#').$safe(testName.getMethodName()).$(); |
| 101 | TestUtils.removeTestPath(root); |
| 102 | OFF_POOL_READER_ID.set(0); |
| 103 | SqlCodeGenerator.ALLOW_FUNCTION_MEMOIZATION = false; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Builds a {@link QueryAssertion} for tests that have no ambient {@link CairoEngine} (e.g. those |
| 108 | * that drive a {@link TestServerMain}). The caller MUST supply the engine and execution context |
| 109 | * via {@link QueryAssertion#withEngine} / {@link QueryAssertion#withContext} before the terminal, |
| 110 | * typically from {@code serverMain.getEngine()} / {@code serverMain.getSqlExecutionContext()}. |
| 111 | * {@link AbstractCairoTest} overrides this with a variant bound to its own static engine. |
| 112 | */ |
| 113 | protected QueryAssertion assertQuery(CharSequence query) { |
| 114 | return new QueryAssertion(null, null, () -> { |
| 115 | }, query); |
| 116 | } |
| 117 |
nothing calls this directly
no test coverage detected
searching dependent graphs…