diff --git a/src/main/java/com/salesforce/scoot/parser/HBaseScootXMLParser.java b/src/main/java/com/salesforce/scoot/parser/HBaseScootXMLParser.java index 8b86539..3bdde85 100644 --- a/src/main/java/com/salesforce/scoot/parser/HBaseScootXMLParser.java +++ b/src/main/java/com/salesforce/scoot/parser/HBaseScootXMLParser.java @@ -79,6 +79,8 @@ public class HBaseScootXMLParser extends HBaseSchemaParser { propertyNames.put("blockSizeKB", HBaseSchemaAttribute.BLOCKSIZE.name()); propertyNames.put("bloomFilter", HBaseSchemaAttribute.BLOOMFILTER.name()); propertyNames.put("inMemory", HBaseSchemaAttribute.IN_MEMORY.name()); + propertyNames.put("keepDeletedCells", HBaseSchemaAttribute.KEEP_DELETED_CELLS.name()); + propertyNames.put("minVersions", HBaseSchemaAttribute.MIN_VERSIONS.name()); propertyNames.put("maxVersions", HBaseSchemaAttribute.VERSIONS.name()); propertyNames.put("replicationScope", HBaseSchemaAttribute.REPLICATION_SCOPE.name()); propertyNames.put("timeToLiveMS", HBaseSchemaAttribute.TTL.name()); diff --git a/src/main/java/com/salesforce/scoot/scripter/HBaseRubySchemaPatchScripter.java b/src/main/java/com/salesforce/scoot/scripter/HBaseRubySchemaPatchScripter.java index fe74fa8..d1bc095 100644 --- a/src/main/java/com/salesforce/scoot/scripter/HBaseRubySchemaPatchScripter.java +++ b/src/main/java/com/salesforce/scoot/scripter/HBaseRubySchemaPatchScripter.java @@ -225,7 +225,8 @@ private void scriptVerifyTableMatches(HTableDescriptor oldTable, String operatio // now descend into child objects for (HColumnDescriptor c : oldTable.getColumnFamilies()){ s(" # Column family: " + c.getNameAsString()); - s(" cf = HColumnDescriptor.new(\"" + c.getNameAsString() + "\")"); + s(" cfname = \"" + c.getNameAsString() + "\""); + s(" cf = table.getFamily(cfname.bytes.to_a)"); for (Entry p : getSortedStringEntries(c.getValues())){ s(" compare(" + errorCollectionName + ", cf, \"" + operationName + "\", \"" + p.getKey() + "\", \"" + escapeDoubleQuotes(p.getValue()) + "\")"); diff --git a/src/test/java/com/salesforce/scoot/ScootTest.java b/src/test/java/com/salesforce/scoot/ScootTest.java index e468fe2..b72eafd 100644 --- a/src/test/java/com/salesforce/scoot/ScootTest.java +++ b/src/test/java/com/salesforce/scoot/ScootTest.java @@ -27,10 +27,18 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import org.apache.hadoop.hbase.util.Bytes; +import java.net.URL; +import java.util.List; import junit.framework.TestCase; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.util.Bytes; + +import com.google.common.io.Resources; +import com.salesforce.scoot.parser.HBaseScootXMLParser; + /** * General tests for scoot functionality * @@ -65,4 +73,42 @@ public void testHelp() throws Exception { } } + + public void testParse() throws Exception { + URL xmlFile = Resources.getResource("ScootXMLParserTest.xml"); + String fileName = xmlFile.getFile(); + HBaseScootXMLParser parser = new HBaseScootXMLParser(); + parser.setResourceToParse(fileName); + HBaseSchema schema = parser.parse(); + + List tables = schema.getTables(); + assertEquals(1, tables.size()); + + // Test table attributes + HTableDescriptor table = tables.get(0); + assertEquals("testMe", table.getNameAsString()); + assertEquals("536870912", table.getValue(HBaseSchemaAttribute.MAX_FILESIZE.name())); + assertEquals("true", table.getValue(HBaseSchemaAttribute.READONLY.name())); + assertEquals("128974848", table.getValue(HBaseSchemaAttribute.MEMSTORE_FLUSHSIZE.name())); + assertEquals("true", table.getValue(HBaseSchemaAttribute.DEFERRED_LOG_FLUSH.name())); + assertEquals("ivarley", table.getOwnerString()); + + HColumnDescriptor[] columnFamilies = table.getColumnFamilies(); + assertNotNull(columnFamilies); + assertEquals(1, columnFamilies.length); + + // Test column family attributes + HColumnDescriptor columnFamily = columnFamilies[0]; + assertEquals("testMeColumnFamily1", columnFamily.getNameAsString()); + assertEquals("10", columnFamily.getValue(HBaseSchemaAttribute.VERSIONS.name())); + assertEquals("32768", columnFamily.getValue(HBaseSchemaAttribute.BLOCKSIZE.name())); + assertEquals("false", columnFamily.getValue(HBaseSchemaAttribute.BLOCKCACHE.name())); + assertEquals("123456789", columnFamily.getValue(HBaseSchemaAttribute.TTL.name())); + assertEquals("true", columnFamily.getValue(HBaseSchemaAttribute.IN_MEMORY.name())); + assertEquals("ROW", columnFamily.getValue(HBaseSchemaAttribute.BLOOMFILTER.name())); + assertEquals("true", columnFamily.getValue(HBaseSchemaAttribute.KEEP_DELETED_CELLS.name())); + assertEquals("5", columnFamily.getValue(HBaseSchemaAttribute.MIN_VERSIONS.name())); + assertEquals("1", columnFamily.getValue(HBaseSchemaAttribute.REPLICATION_SCOPE.name())); + + } } diff --git a/src/test/resources/DiffScriptGenerationTestResultAB.rb b/src/test/resources/DiffScriptGenerationTestResultAB.rb index 1c7dced..af549a1 100644 --- a/src/test/resources/DiffScriptGenerationTestResultAB.rb +++ b/src/test/resources/DiffScriptGenerationTestResultAB.rb @@ -75,7 +75,8 @@ def compare(errs, obj, action, attr, val) compare(preWarnings, table, "drop", "READONLY", "false") compare(preWarnings, table, "drop", "fullSchema", "
") # Column family: dropMeColumnFamily1 - cf = HColumnDescriptor.new("dropMeColumnFamily1") + cfname = "dropMeColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preWarnings, cf, "drop", "BLOCKCACHE", "true") compare(preWarnings, cf, "drop", "BLOCKSIZE", "65536") compare(preWarnings, cf, "drop", "BLOOMFILTER", "NONE") @@ -114,7 +115,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: alterMeColumnFamily1 - cf = HColumnDescriptor.new("alterMeColumnFamily1") + cfname = "alterMeColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "65536") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") @@ -258,7 +260,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "create", "READONLY", "false") compare(preErrors, table, "create", "fullSchema", "
") # Column family: createMeColumnFamily1 - cf = HColumnDescriptor.new("createMeColumnFamily1") + cfname = "createMeColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "create", "BLOCKCACHE", "true") compare(preErrors, cf, "create", "BLOCKSIZE", "65536") compare(preErrors, cf, "create", "BLOOMFILTER", "NONE") @@ -291,7 +294,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: alterMeColumnFamily1 - cf = HColumnDescriptor.new("alterMeColumnFamily1") + cfname = "alterMeColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "66560") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") diff --git a/src/test/resources/DiffScriptGenerationTestResultD.rb b/src/test/resources/DiffScriptGenerationTestResultD.rb index 02de001..039502f 100644 --- a/src/test/resources/DiffScriptGenerationTestResultD.rb +++ b/src/test/resources/DiffScriptGenerationTestResultD.rb @@ -67,7 +67,8 @@ def compare(errs, obj, action, attr, val) compare(preWarnings, table, "drop", "READONLY", "false") compare(preWarnings, table, "drop", "fullSchema", "
") # Column family: createMeColumnFamily1 - cf = HColumnDescriptor.new("createMeColumnFamily1") + cfname = "createMeColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preWarnings, cf, "drop", "BLOCKCACHE", "true") compare(preWarnings, cf, "drop", "BLOCKSIZE", "65536") compare(preWarnings, cf, "drop", "BLOOMFILTER", "NONE") diff --git a/src/test/resources/DiffScriptGenerationTestResultEF.rb b/src/test/resources/DiffScriptGenerationTestResultEF.rb index 66b6013..4fd5bc3 100644 --- a/src/test/resources/DiffScriptGenerationTestResultEF.rb +++ b/src/test/resources/DiffScriptGenerationTestResultEF.rb @@ -67,7 +67,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: minimalColumnFamily1 - cf = HColumnDescriptor.new("minimalColumnFamily1") + cfname = "minimalColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "65536") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") @@ -160,7 +161,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: minimalColumnFamily1 - cf = HColumnDescriptor.new("minimalColumnFamily1") + cfname = "minimalColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "65536") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") diff --git a/src/test/resources/DiffScriptGenerationTestResultFE.rb b/src/test/resources/DiffScriptGenerationTestResultFE.rb index 6441a42..363760b 100644 --- a/src/test/resources/DiffScriptGenerationTestResultFE.rb +++ b/src/test/resources/DiffScriptGenerationTestResultFE.rb @@ -67,7 +67,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: minimalColumnFamily1 - cf = HColumnDescriptor.new("minimalColumnFamily1") + cfname = "minimalColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "65536") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") @@ -160,7 +161,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "alter", "READONLY", "false") compare(preErrors, table, "alter", "fullSchema", "
") # Column family: minimalColumnFamily1 - cf = HColumnDescriptor.new("minimalColumnFamily1") + cfname = "minimalColumnFamily1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "alter", "BLOCKCACHE", "true") compare(preErrors, cf, "alter", "BLOCKSIZE", "65536") compare(preErrors, cf, "alter", "BLOOMFILTER", "NONE") diff --git a/src/test/resources/PhoenixScriptGenerationTestResultA.rb b/src/test/resources/PhoenixScriptGenerationTestResultA.rb index 3445c0b..0b2c8ff 100644 --- a/src/test/resources/PhoenixScriptGenerationTestResultA.rb +++ b/src/test/resources/PhoenixScriptGenerationTestResultA.rb @@ -142,7 +142,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, table, "create", "MEMSTORE_FLUSHSIZE", "134217728") compare(preErrors, table, "create", "READONLY", "false") # Column family: 1 - cf = HColumnDescriptor.new("1") + cfname = "1" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "create", "BLOCKCACHE", "true") compare(preErrors, cf, "create", "BLOCKSIZE", "65536") compare(preErrors, cf, "create", "BLOOMFILTER", "NONE") @@ -156,7 +157,8 @@ def compare(errs, obj, action, attr, val) compare(preErrors, cf, "create", "TTL", "2147483647") compare(preErrors, cf, "create", "VERSIONS", "3") # Column family: 2 - cf = HColumnDescriptor.new("2") + cfname = "2" + cf = table.getFamily(cfname.bytes.to_a) compare(preErrors, cf, "create", "BLOCKCACHE", "true") compare(preErrors, cf, "create", "BLOCKSIZE", "65536") compare(preErrors, cf, "create", "BLOOMFILTER", "NONE") diff --git a/src/test/resources/ScootXMLParserTest.xml b/src/test/resources/ScootXMLParserTest.xml new file mode 100644 index 0000000..f62f46e --- /dev/null +++ b/src/test/resources/ScootXMLParserTest.xml @@ -0,0 +1,25 @@ + + + + + + + + +
+ +