[HUDI-564] Added new test cases for HoodieLogFormat and HoodieLogFormatVersion.
This commit is contained in:
33
hudi-common/src/test/java/org/apache/hudi/common/table/log/TestHoodieLogFormat.java
Normal file → Executable file
33
hudi-common/src/test/java/org/apache/hudi/common/table/log/TestHoodieLogFormat.java
Normal file → Executable file
@@ -414,6 +414,7 @@ public class TestHoodieLogFormat extends HoodieCommonTestHarness {
|
|||||||
dataBlockRead.getRecords().size());
|
dataBlockRead.getRecords().size());
|
||||||
assertEquals("Both records lists should be the same. (ordering guaranteed)", copyOfRecords1,
|
assertEquals("Both records lists should be the same. (ordering guaranteed)", copyOfRecords1,
|
||||||
dataBlockRead.getRecords());
|
dataBlockRead.getRecords());
|
||||||
|
assertEquals(dataBlockRead.getSchema(), getSimpleSchema());
|
||||||
|
|
||||||
reader.hasNext();
|
reader.hasNext();
|
||||||
nextBlock = reader.next();
|
nextBlock = reader.next();
|
||||||
@@ -1389,4 +1390,36 @@ public class TestHoodieLogFormat extends HoodieCommonTestHarness {
|
|||||||
assertFalse(reader.hasPrev());
|
assertFalse(reader.hasPrev());
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testV0Format() throws IOException, InterruptedException, URISyntaxException {
|
||||||
|
// HoodieLogFormatVersion.DEFAULT_VERSION has been deprecated so we cannot
|
||||||
|
// create a writer for it. So these tests are only for the HoodieAvroDataBlock
|
||||||
|
// of older version.
|
||||||
|
Schema schema = getSimpleSchema();
|
||||||
|
List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
|
||||||
|
List<IndexedRecord> recordsCopy = new ArrayList<>(records);
|
||||||
|
assertEquals(records.size(), 100);
|
||||||
|
assertEquals(recordsCopy.size(), 100);
|
||||||
|
HoodieAvroDataBlock dataBlock = new HoodieAvroDataBlock(records, schema);
|
||||||
|
byte[] content = dataBlock.getBytes(schema);
|
||||||
|
assertTrue(content.length > 0);
|
||||||
|
|
||||||
|
HoodieLogBlock logBlock = HoodieAvroDataBlock.getBlock(content, schema);
|
||||||
|
assertEquals(logBlock.getBlockType(), HoodieLogBlockType.AVRO_DATA_BLOCK);
|
||||||
|
List<IndexedRecord> readRecords = ((HoodieAvroDataBlock)logBlock).getRecords();
|
||||||
|
assertEquals(readRecords.size(), recordsCopy.size());
|
||||||
|
for (int i = 0; i < recordsCopy.size(); ++i) {
|
||||||
|
assertEquals(recordsCopy.get(i), readRecords.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reader schema is optional if it is same as write schema
|
||||||
|
logBlock = HoodieAvroDataBlock.getBlock(content, null);
|
||||||
|
assertEquals(logBlock.getBlockType(), HoodieLogBlockType.AVRO_DATA_BLOCK);
|
||||||
|
readRecords = ((HoodieAvroDataBlock)logBlock).getRecords();
|
||||||
|
assertEquals(readRecords.size(), recordsCopy.size());
|
||||||
|
for (int i = 0; i < recordsCopy.size(); ++i) {
|
||||||
|
assertEquals(recordsCopy.get(i), readRecords.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hudi.common.table.log;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests HUDI log format version {@link HoodieLogFormatVersion}.
|
||||||
|
*/
|
||||||
|
public class TestHoodieLogFormatVersion {
|
||||||
|
private static HoodieLogFormatVersion verDefault =
|
||||||
|
new HoodieLogFormatVersion(HoodieLogFormatVersion.DEFAULT_VERSION);
|
||||||
|
private static HoodieLogFormatVersion verCurrent =
|
||||||
|
new HoodieLogFormatVersion(HoodieLogFormat.CURRENT_VERSION);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasMagicHeader() {
|
||||||
|
assertTrue(verDefault.hasMagicHeader());
|
||||||
|
assertTrue(verCurrent.hasMagicHeader());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasContent() {
|
||||||
|
assertTrue(verDefault.hasContent());
|
||||||
|
assertTrue(verCurrent.hasContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasContentLength() {
|
||||||
|
assertTrue(verDefault.hasContentLength());
|
||||||
|
assertTrue(verCurrent.hasContentLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasOrdinal() {
|
||||||
|
assertTrue(verDefault.hasOrdinal());
|
||||||
|
assertTrue(verCurrent.hasOrdinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasHeader() {
|
||||||
|
assertFalse(verDefault.hasHeader());
|
||||||
|
assertTrue(verCurrent.hasHeader());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasFooter() {
|
||||||
|
assertFalse(verDefault.hasFooter());
|
||||||
|
assertTrue(verCurrent.hasFooter());
|
||||||
|
|
||||||
|
HoodieLogFormatVersion verNew =
|
||||||
|
new HoodieLogFormatVersion(HoodieLogFormat.CURRENT_VERSION + 1);
|
||||||
|
assertFalse(verNew.hasFooter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasLogBlockLength() {
|
||||||
|
assertFalse(verDefault.hasLogBlockLength());
|
||||||
|
assertTrue(verCurrent.hasLogBlockLength());
|
||||||
|
|
||||||
|
HoodieLogFormatVersion verNew =
|
||||||
|
new HoodieLogFormatVersion(HoodieLogFormat.CURRENT_VERSION + 1);
|
||||||
|
assertFalse(verNew.hasLogBlockLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user