Skip to content

Commit bdea154

Browse files
hantangwangdshrinidhijoshi
authored andcommitted
Fix flaky test in TestHiveCommitHandleOutput
1 parent 14f9ff7 commit bdea154

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

presto-hive/src/test/java/com/facebook/presto/hive/TestHiveCommitHandleOutput.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,31 @@ public void testCommitOutputForPartitions()
206206
assertEquals(handle.getSerializedCommitOutputForRead(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), serializedCommitOutput);
207207
assertTrue(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)).isEmpty());
208208

209+
// Add the same partition with the same location, the metastore will generate same commit output.
210+
hiveMeta = getHiveMetadata(metastore, hiveClientConfig, listeningExecutor);
211+
hiveMeta.getMetastore().addPartition(
212+
connectorSession,
213+
TEST_SCHEMA,
214+
TEST_TABLE,
215+
"random_table_path",
216+
false,
217+
createPartition(partitionName, "location1"),
218+
new Path("/" + TEST_TABLE),
219+
PartitionStatistics.empty());
220+
handle = hiveMeta.commit();
221+
222+
assertEquals(handle.getSerializedCommitOutputForRead(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), "");
223+
assertFalse(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)).isEmpty());
224+
assertEquals(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), serializedCommitOutput);
225+
209226
// Add the same partition with different location, it should trigger the metastore to generate different commit output.
227+
// Wait for 1000ms to make sure the commit time changes
228+
try {
229+
Thread.sleep(1000);
230+
}
231+
catch (InterruptedException e) {
232+
// ignored
233+
}
210234
hiveMeta = getHiveMetadata(metastore, hiveClientConfig, listeningExecutor);
211235
hiveMeta.getMetastore().addPartition(
212236
connectorSession,
@@ -221,7 +245,7 @@ public void testCommitOutputForPartitions()
221245

222246
assertEquals(handle.getSerializedCommitOutputForRead(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), "");
223247
assertFalse(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)).isEmpty());
224-
assertEquals(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE)), serializedCommitOutput);
248+
assertTrue(Long.parseLong(handle.getSerializedCommitOutputForWrite(new SchemaTableName(TEST_SCHEMA, TEST_TABLE))) > Long.parseLong(serializedCommitOutput));
225249
}
226250

227251
private HiveMetadata getHiveMetadata(TestingExtendedHiveMetastore metastore, HiveClientConfig hiveClientConfig, ListeningExecutorService listeningExecutor)

0 commit comments

Comments
 (0)