| 67 | import java.util.concurrent.TimeUnit; |
| 68 | |
| 69 | public class Table2IlpTest { |
| 70 | private static final int HTTP_PORT = 9900; |
| 71 | private static final int ILP_PORT = 9909; |
| 72 | private static final Log LOG = LogFactory.getLog(Table2IlpTest.class); |
| 73 | @ClassRule |
| 74 | public static TemporaryFolder temp = new TemporaryFolder(); |
| 75 | protected static CharSequence root; |
| 76 | private static DefaultCairoConfiguration configuration; |
| 77 | private static CairoEngine engine; |
| 78 | private static HttpServer httpServer; |
| 79 | private static PGServer pgServer; |
| 80 | private static LineTcpReceiver receiver; |
| 81 | private static SqlExecutionContextImpl sqlExecutionContext; |
| 82 | private static WorkerPool workerPool; |
| 83 | |
| 84 | public static void assertEventually(Runnable assertion, int timeoutSeconds) { |
| 85 | long maxSleepingTimeMillis = 1000; |
| 86 | long nextSleepingTimeMillis = 10; |
| 87 | long startTime = System.nanoTime(); |
| 88 | long deadline = startTime + TimeUnit.SECONDS.toNanos(timeoutSeconds); |
| 89 | for (; ; ) { |
| 90 | try { |
| 91 | assertion.run(); |
| 92 | return; |
| 93 | } catch (AssertionError error) { |
| 94 | if (System.nanoTime() >= deadline) { |
| 95 | throw error; |
| 96 | } |
| 97 | } |
| 98 | Os.sleep(nextSleepingTimeMillis); |
| 99 | nextSleepingTimeMillis = Math.min(maxSleepingTimeMillis, nextSleepingTimeMillis << 1); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | public static void createTestPath(CharSequence root) { |
| 104 | try (Path path = new Path().of(root)) { |
| 105 | if (Files.exists(path.$())) { |
| 106 | return; |
| 107 | } |
| 108 | Files.mkdirs(path.of(root).slash(), 509); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | public static void removeTestPath(CharSequence root) { |
| 113 | Path path = Path.getThreadLocal(root); |
| 114 | Files.rmdir(path.slash(), true); |
| 115 | } |
| 116 | |
| 117 | public static void setCairoStatic() { |
| 118 | // it is necessary to initialise logger before tests start |
| 119 | // logger doesn't relinquish memory until JVM stops |
| 120 | // which causes memory leak detector to fail should logger be |
| 121 | // created mid-test |
| 122 | try { |
| 123 | root = temp.newFolder("dbRoot").getAbsolutePath(); |
| 124 | } catch (IOException e) { |
| 125 | throw new ExceptionInInitializerError(); |
| 126 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…