### Question:
PartitionerCache { public List<String> validatePartitioners(String[] tableNames, Job job) { ArrayList<String> validTableNames = new ArrayList<>(); for (String tableName : tableNames) { if (hasPartitionerOverride(new Text(tableName))) { try { Partitioner<BulkIngestKey,Value> partitionerForTable = cachePartitioner(new Text(tableName)); initializeJob(job, partitionerForTable); validTableNames.add(tableName); } catch (Exception e) { log.warn("Unable to create the partitioner for " + tableName + " despite its configuration." + "Will use the default partitioner for this table.", e); lazyInitializeDefaultPartitioner(job); } } else { lazyInitializeDefaultPartitioner(job); } } return validTableNames; } PartitionerCache(Configuration conf); List<String> validatePartitioners(String[] tableNames, Job job); void createAndCachePartitioners(List<Text> tableNames); Partitioner<BulkIngestKey,Value> getPartitioner(Text tableName); static Text getCategory(Configuration conf, Text tableName);  }### Answer:
@Test public void testValidateWillFilterOutTablesWithoutConfigurations() throws Exception { conf.set(PartitionerCache.PREFIX_DEDICATED_PARTITIONER + "table1", DelegatingPartitionerTest.AlwaysReturnOne.class.getName()); cache = new PartitionerCache(conf); List<String> result = cache.validatePartitioners(new String[] {"table1", "table2"}, new Job(conf)); Assert.assertTrue(result.contains("table1")); Assert.assertFalse("table2 partitioner class name is missing from the conf, yet it was not filtered out", result.contains("table2")); }
@Test public void testValidateExpectedCase() throws Exception { conf.set(PartitionerCache.PREFIX_DEDICATED_PARTITIONER + "table1", DelegatingPartitionerTest.AlwaysReturnOne.class.getName()); conf.set(PartitionerCache.PREFIX_DEDICATED_PARTITIONER + "table2", DelegatingPartitionerTest.AlwaysReturnTwo.class.getName()); cache = new PartitionerCache(conf); List<String> result = cache.validatePartitioners(new String[] {"table1", "table2"}, new Job(conf)); Assert.assertTrue(result.contains("table1")); Assert.assertTrue(result.contains("table2")); }
@Test public void testValidateNoOverrides() throws Exception { List<String> result = new PartitionerCache(conf).validatePartitioners(new String[] {"table1", "table2"}, new Job(conf)); Assert.assertEquals("None of the tables were configured, so the overrides list should be empty", result.size(), 0); }
@Test public void testValidateWillFilterBadlyConfiguredTablesWithoutThrowingException() throws Exception { conf.set(PartitionerCache.PREFIX_DEDICATED_PARTITIONER + "table1", DelegatingPartitionerTest.AlwaysReturnOne.class.getName()); conf.set(PartitionerCache.PREFIX_DEDICATED_PARTITIONER + "table2", PartitionerThatMustNotBeCreated.class.getName()); cache = new PartitionerCache(conf); List<String> result = new PartitionerCache(conf).validatePartitioners(new String[] {"table1", "table2"}, new Job(conf)); Assert.assertTrue(result.contains("table1")); Assert.assertFalse("table2's partitioner cannot be created, so it should be removed from the list", result.contains("table2")); }