/** * Test characteristic set reduction * * @throws IOException */ @Test public void characteristic_set_reducer_04() throws IOException { MapReduceDriver< CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, CharacteristicSetWritable, NullWritable> driver = this.getMapReduceDriver(); this.createSet(driver, 2, 1, "http://predicate"); this.createSet(driver, 1, 1, "http://other"); driver.runTest(false); driver = getMapReduceDriver(); createSet(driver, 2, 1, "http://predicate"); createSet(driver, 1, 1, "http://other"); List<Pair<CharacteristicSetWritable, NullWritable>> results = driver.run(); for (Pair<CharacteristicSetWritable, NullWritable> pair : results) { CharacteristicSetWritable cw = pair.getFirst(); boolean expectTwo = cw.getCharacteristics().next().getNode().get().hasURI("http://predicate"); Assert.assertEquals(expectTwo ? 2 : 1, cw.getCount().get()); } }
/** * Checks a characteristic set * * @param set Set * @param expectedItems Expected number of characteristics * @param expectedCounts Expected counts for characteristics */ protected final void checkCharacteristicSet( CharacteristicSetWritable set, int expectedItems, long[] expectedCounts) { Assert.assertEquals(expectedItems, set.size()); Assert.assertEquals(expectedItems, expectedCounts.length); Iterator<CharacteristicWritable> iter = set.getCharacteristics(); int i = 0; while (iter.hasNext()) { CharacteristicWritable cw = iter.next(); Assert.assertEquals(expectedCounts[i], cw.getCount().get()); i++; } }