}
@Test
public void testBulkFileCheck() {
MetadataConstraints mc = new TestMetadataConstraints();
Mutation m;
List<Short> violations;
// inactive txid
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("12345".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
violations = mc.check(null, m);
assertNotNull(violations);
assertEquals(1, violations.size());
assertEquals(Short.valueOf((short) 8), violations.get(0));
// txid that throws exception
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("9".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
violations = mc.check(null, m);
assertNotNull(violations);
assertEquals(1, violations.size());
assertEquals(Short.valueOf((short) 8), violations.get(0));
// active txid w/ file
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// active txid w/o file
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
violations = mc.check(null, m);
assertNotNull(violations);
assertEquals(1, violations.size());
assertEquals(Short.valueOf((short) 8), violations.get(0));
// two active txids w/ files
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile2"), new Value("7".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile2"), new Value("1,1".getBytes()));
violations = mc.check(null, m);
assertNotNull(violations);
assertEquals(1, violations.size());
assertEquals(Short.valueOf((short) 8), violations.get(0));
// two files w/ one active txid
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile2"), new Value("5".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile2"), new Value("1,1".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// two loaded w/ one active txid and one file
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
m.put(DataFileColumnFamily.NAME, new Text("/someFile"), new Value("1,1".getBytes()));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile2"), new Value("5".getBytes()));
violations = mc.check(null, m);
assertNotNull(violations);
assertEquals(1, violations.size());
assertEquals(Short.valueOf((short) 8), violations.get(0));
// active txid, mutation that looks like split
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value("/t1".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// inactive txid, mutation that looks like split
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("12345".getBytes()));
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value("/t1".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// active txid, mutation that looks like a load
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("5".getBytes()));
m.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("789"), new Value("127.0.0.1:9997".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// inactive txid, mutation that looks like a load
m = new Mutation(new Text("0;foo"));
m.put(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"), new Value("12345".getBytes()));
m.put(TabletsSection.CurrentLocationColumnFamily.NAME, new Text("789"), new Value("127.0.0.1:9997".getBytes()));
violations = mc.check(null, m);
assertNull(violations);
// deleting a load flag
m = new Mutation(new Text("0;foo"));
m.putDelete(TabletsSection.BulkFileColumnFamily.NAME, new Text("/someFile"));
violations = mc.check(null, m);
assertNull(violations);
}