/** Test that comparator is defined and configured. */ public static void testGetComparator() throws Exception { Configuration conf = new Configuration(); // Without conf. WritableComparator frobComparator = WritableComparator.get(Frob.class); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertNull(frobComparator.getConf().get(TEST_CONFIG_PARAM)); // With conf. conf.set(TEST_CONFIG_PARAM, TEST_CONFIG_VALUE); frobComparator = WritableComparator.get(Frob.class, conf); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertEquals(conf.get(TEST_CONFIG_PARAM), TEST_CONFIG_VALUE); // Without conf. should reuse configuration. frobComparator = WritableComparator.get(Frob.class); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertEquals(conf.get(TEST_CONFIG_PARAM), TEST_CONFIG_VALUE); // New conf. should use new configuration. frobComparator = WritableComparator.get(Frob.class, new Configuration()); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertNull(frobComparator.getConf().get(TEST_CONFIG_PARAM)); }
/** Test that comparator is defined and configured. */ public static void testGetComparator() throws Exception { Configuration conf = new Configuration(); // Without conf. WritableComparator frobComparator = WritableComparator.get(Frob.class); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertNull(frobComparator.getConf().get(TEST_CONFIG_PARAM)); // With conf. conf.set(TEST_CONFIG_PARAM, TEST_CONFIG_VALUE); frobComparator = WritableComparator.get(Frob.class, conf); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertEquals(conf.get(TEST_CONFIG_PARAM), TEST_CONFIG_VALUE); // Without conf. should reuse configuration. frobComparator = WritableComparator.get(Frob.class); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertEquals(conf.get(TEST_CONFIG_PARAM), TEST_CONFIG_VALUE); // New conf. should use new configuration. frobComparator = WritableComparator.get(Frob.class, new Configuration()); assert(frobComparator instanceof FrobComparator); assertNotNull(frobComparator.getConf()); assertNull(frobComparator.getConf().get(TEST_CONFIG_PARAM)); }
/** * Test that Writable's are configured by Comparator. */ public void testConfigurableWritableComparator() throws Exception { Configuration conf = new Configuration(); conf.set(TEST_WRITABLE_CONFIG_PARAM, TEST_WRITABLE_CONFIG_VALUE); WritableComparator wc = WritableComparator.get(SimpleWritableComparable.class, conf); SimpleWritableComparable key = ((SimpleWritableComparable)wc.newKey()); assertNotNull(wc.getConf()); assertNotNull(key.getConf()); assertEquals(key.getConf().get(TEST_WRITABLE_CONFIG_PARAM), TEST_WRITABLE_CONFIG_VALUE); } }
/** * Test that Writable's are configured by Comparator. */ public void testConfigurableWritableComparator() throws Exception { Configuration conf = new Configuration(); conf.set(TEST_WRITABLE_CONFIG_PARAM, TEST_WRITABLE_CONFIG_VALUE); WritableComparator wc = WritableComparator.get(SimpleWritableComparable.class, conf); SimpleWritableComparable key = ((SimpleWritableComparable)wc.newKey()); assertNotNull(wc.getConf()); assertNotNull(key.getConf()); assertEquals(key.getConf().get(TEST_WRITABLE_CONFIG_PARAM), TEST_WRITABLE_CONFIG_VALUE); } }