Skip to content

Commit 76e3776

Browse files
test: make org.apache.gora.hive.store.TestHiveStore deterministic
1 parent cc01c18 commit 76e3776

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

gora-hive/src/test/java/org/apache/gora/hive/store/TestHiveStore.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.charset.Charset;
2525
import java.util.ArrayList;
2626
import java.util.Set;
27+
import java.util.concurrent.TimeUnit;
2728
import org.apache.avro.util.Utf8;
2829
import org.apache.gora.examples.generated.Employee;
2930
import org.apache.gora.examples.generated.Metadata;
@@ -53,7 +54,35 @@ public class TestHiveStore extends DataStoreTestBase {
5354

5455
@Override
5556
public void assertSchemaExists(String schemaName) throws Exception {
56-
assertTrue(employeeStore.schemaExists());
57+
if ("Employee".equals(schemaName)) {
58+
assertTrue(employeeStore.schemaExists());
59+
return;
60+
}
61+
// Include WebPage because base tests call assertSchemaExists("WebPage") in DataStoreTestBase#testTruncateSchema.
62+
if ("WebPage".equals(schemaName)) {
63+
assertTrue(webPageStore.schemaExists());
64+
return;
65+
}
66+
throw new AssertionError("unsupported schema name: " + schemaName);
67+
}
68+
69+
@Override
70+
public void assertAutoCreateSchema() throws Exception {
71+
// Poll briefly for Hive metastore visibility only in the auto-create scenario.
72+
final long timeoutNanos = TimeUnit.SECONDS.toNanos(5);
73+
final long sleepMillis = 100L;
74+
long deadline = System.nanoTime() + timeoutNanos;
75+
employeeStore.flush();
76+
while (System.nanoTime() < deadline) {
77+
if (employeeStore.schemaExists()) {
78+
assertSchemaExists(((HiveStore<String, Employee>) employeeStore).getSchemaName());
79+
return;
80+
}
81+
TimeUnit.MILLISECONDS.sleep(sleepMillis);
82+
employeeStore.flush();
83+
}
84+
// If still not visible by timeout, fail via the original assertion.
85+
assertSchemaExists(((HiveStore<String, Employee>) employeeStore).getSchemaName());
5786
}
5887

5988
@Override

0 commit comments

Comments
 (0)