MCPcopy Index your code
hub / github.com/questdb/questdb / AbstractTest

Class AbstractTest

compat/src/test/java/io/questdb/compat/AbstractTest.java:51–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49import java.util.concurrent.TimeUnit;
50
51public class AbstractTest {
52 @ClassRule
53 public static final TemporaryFolder temp = new TemporaryFolder();
54 protected static final Log LOG = LogFactory.getLog(AbstractTest.class);
55 protected static String root;
56 @Rule
57 public final TestName testName = new TestName();
58 protected final StringSink sink = new StringSink();
59
60 public static void assertEventually(Runnable assertion) {
61 assertEventually(assertion, 30);
62 }
63
64 public static void assertEventually(Runnable assertion, int timeoutSeconds) {
65 long maxSleepingTimeMillis = 1000;
66 long nextSleepingTimeMillis = 10;
67 long startTime = System.nanoTime();
68 long deadline = startTime + TimeUnit.SECONDS.toNanos(timeoutSeconds);
69 for (; ; ) {
70 try {
71 assertion.run();
72 return;
73 } catch (AssertionError error) {
74 if (System.nanoTime() >= deadline) {
75 throw error;
76 }
77 }
78 Os.sleep(nextSleepingTimeMillis);
79 nextSleepingTimeMillis = Math.min(maxSleepingTimeMillis, nextSleepingTimeMillis << 1);
80 }
81 }
82
83 public static void createTestPath() {
84 final Path path = Path.getThreadLocal(root);
85 if (Files.exists(path.$())) {
86 return;
87 }
88 Files.mkdirs(path.of(root).slash(), 509);
89 }
90
91 public static Rnd generateRandom(Log log) {
92 return generateRandom(log, System.nanoTime(), System.currentTimeMillis());
93 }
94
95 public static Rnd generateRandom(Log log, long s0, long s1) {
96 if (log != null) {
97 log.info().$("random seeds: ").$(s0).$("L, ").$(s1).$('L').$();
98 }
99 System.out.printf("random seeds: %dL, %dL%n", s0, s1);
100 return new Rnd(s0, s1);
101 }
102
103 public static void removeTestPath() {
104 final Path path = Path.getThreadLocal(root);
105 FilesFacade ff = FilesFacadeImpl.INSTANCE;
106 path.slash$();
107 Assert.assertTrue("Test dir cleanup error", !ff.exists(path.$()) || Files.rmdir(path.slash(), true));
108 }

Callers

nothing calls this directly

Calls 1

getLogMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…