/**
   * Test characteristic set reduction
   *
   * @throws IOException
   */
  @Test
  public void characteristic_set_reducer_06() throws IOException {
    MapReduceDriver<
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            NullWritable>
        driver = this.getMapReduceDriver();

    this.createSet(driver, 2, 1, "http://predicate", "http://other");
    this.createSet(driver, 1, 1, "http://other");
    driver.runTest(false);

    driver = getMapReduceDriver();
    createSet(driver, 2, 1, "http://predicate", "http://other");
    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.hasCharacteristic("http://predicate");
      Assert.assertEquals(expectTwo ? 2 : 1, cw.getCount().get());
    }
  }
Ejemplo n.º 2
0
  /**
   * Checks that a writable round trips
   *
   * @param set Characteristic set
   * @throws IOException
   */
  private void checkRoundTrip(CharacteristicSetWritable set) throws IOException {
    // Test round trip
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutputStream output = new DataOutputStream(outputStream);
    set.write(output);

    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    DataInputStream input = new DataInputStream(inputStream);
    CharacteristicSetWritable actual = CharacteristicSetWritable.read(input);
    Assert.assertEquals(set, actual);
  }
Ejemplo n.º 3
0
 /**
  * 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++;
   }
 }
Ejemplo n.º 4
0
  /**
   * Tests characteristic sets
   *
   * @throws IOException
   */
  @Test
  public void characteristic_set_writable_02() throws IOException {
    CharacteristicSetWritable set = new CharacteristicSetWritable();

    // Add some characteristics
    CharacteristicWritable cw1 =
        new CharacteristicWritable(NodeFactory.createURI("http://example.org"));
    CharacteristicWritable cw2 =
        new CharacteristicWritable(NodeFactory.createURI("http://example.org"), 2);
    set.add(cw1);
    set.add(cw2);
    this.checkCharacteristicSet(set, 1, new long[] {3});
    this.checkRoundTrip(set);
  }
Ejemplo n.º 5
0
  /**
   * Tests characteristic sets
   *
   * @throws IOException
   */
  @Test
  public void characteristic_set_writable_03() throws IOException {
    CharacteristicSetWritable set1 = new CharacteristicSetWritable();
    CharacteristicSetWritable set2 = new CharacteristicSetWritable();

    // Add some characteristics
    CharacteristicWritable cw1 =
        new CharacteristicWritable(NodeFactory.createURI("http://example.org"));
    CharacteristicWritable cw2 =
        new CharacteristicWritable(NodeFactory.createURI("http://example.org/other"));
    set1.add(cw1);
    set2.add(cw2);
    this.checkCharacteristicSet(set1, 1, new long[] {1});
    this.checkCharacteristicSet(set2, 1, new long[] {1});
    this.checkRoundTrip(set1);
    this.checkRoundTrip(set2);

    Assert.assertNotEquals(set1, set2);
  }
  /**
   * Test characteristic set reduction
   *
   * @throws IOException
   */
  @Test
  public void characteristic_set_reducer_02() throws IOException {
    MapReduceDriver<
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            CharacteristicSetWritable,
            NullWritable>
        driver = this.getMapReduceDriver();

    this.createSet(driver, 2, 1, "http://predicate");
    driver.runTest(false);

    driver = getMapReduceDriver();
    createSet(driver, 2, 1, "http://predicate");
    List<Pair<CharacteristicSetWritable, NullWritable>> results = driver.run();
    CharacteristicSetWritable cw = results.get(0).getFirst();
    Assert.assertEquals(2, cw.getCount().get());
  }
 /**
  * Creates a set consisting of the given predicates
  *
  * @param predicates Predicates
  * @return Set
  */
 protected CharacteristicSetWritable createSet(
     MapReduceDriver<
             CharacteristicSetWritable,
             CharacteristicSetWritable,
             CharacteristicSetWritable,
             CharacteristicSetWritable,
             CharacteristicSetWritable,
             NullWritable>
         driver,
     int inputOccurrences,
     int outputOccurrences,
     String... predicates) {
   CharacteristicSetWritable set = new CharacteristicSetWritable();
   for (String predicateUri : predicates) {
     set.add(new CharacteristicWritable(NodeFactory.createURI(predicateUri)));
   }
   for (int i = 1; i <= inputOccurrences; i++) {
     driver.addInput(set, set);
   }
   for (int i = 1; i <= outputOccurrences; i++) {
     driver.addOutput(set, NullWritable.get());
   }
   return set;
 }