Exemplo n.º 1
0
  @Test
  public void testFailingHashSecondMatchTask() {
    int keyCnt1 = 20;
    int valCnt1 = 20;

    int keyCnt2 = 20;
    int valCnt2 = 20;

    addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false));
    addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false));
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    setOutput(new NirvanaOutputList());
    getTaskConfig().setDriverStrategy(DriverStrategy.HYBRIDHASH_BUILD_SECOND);
    getTaskConfig().setMemoryDriver(HASH_MEM);

    MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    try {
      testDriver(testTask, MockFailingMatchStub.class);
      Assert.fail("Stub exception was not forwarded.");
    } catch (ExpectedTestException etex) {
      // good!
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Test caused an exception.");
    }
  }
Exemplo n.º 2
0
  @Test
  public void testHash5MatchTask() {
    int keyCnt1 = 20;
    int valCnt1 = 20;

    int keyCnt2 = 20;
    int valCnt2 = 20;

    addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false));
    addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false));
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    setOutput(this.outList);
    getTaskConfig().setDriverStrategy(DriverStrategy.HYBRIDHASH_BUILD_FIRST);
    getTaskConfig().setMemoryDriver(HASH_MEM);

    MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    try {
      testDriver(testTask, MockMatchStub.class);
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Test caused an exception.");
    }

    final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
    Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
    this.outList.clear();
  }
Exemplo n.º 3
0
  @Test
  public void testFailingMatchTask() {
    int keyCnt1 = 20;
    int valCnt1 = 20;

    int keyCnt2 = 20;
    int valCnt2 = 20;

    setOutput(new NirvanaOutputList());
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    getTaskConfig().setDriverStrategy(DriverStrategy.MERGE);
    getTaskConfig().setMemoryDriver(BNLJN_MEM);
    setNumFileHandlesForSort(4);

    final MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, true));
    addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, true));

    try {
      testDriver(testTask, MockFailingMatchStub.class);
      Assert.fail("Driver did not forward Exception.");
    } catch (ExpectedTestException e) {
      // good!
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("The test caused an exception.");
    }
  }
Exemplo n.º 4
0
  @Test
  public void testCancelMatchTaskWhileSort2() {
    int keyCnt = 20;
    int valCnt = 20;

    setOutput(new NirvanaOutputList());
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    getTaskConfig().setDriverStrategy(DriverStrategy.MERGE);
    getTaskConfig().setMemoryDriver(BNLJN_MEM);
    setNumFileHandlesForSort(4);

    final MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    try {
      addInput(new UniformPactRecordGenerator(keyCnt, valCnt, true));
      addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator1.duplicate());
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("The test caused an exception.");
    }

    final AtomicBoolean success = new AtomicBoolean(false);

    Thread taskRunner =
        new Thread() {
          @Override
          public void run() {
            try {
              testDriver(testTask, MockMatchStub.class);
              success.set(true);
            } catch (Exception ie) {
              ie.printStackTrace();
            }
          }
        };
    taskRunner.start();

    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
    tct.start();

    try {
      tct.join();
      taskRunner.join();
    } catch (InterruptedException ie) {
      Assert.fail("Joining threads failed");
    }

    Assert.assertTrue(
        "Test threw an exception even though it was properly canceled.", success.get());
  }
Exemplo n.º 5
0
  @Test
  public void testHashSecondCancelMatchTaskWhileMatching() {
    int keyCnt = 20;
    int valCnt = 20;

    addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false));
    addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false));
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    setOutput(new NirvanaOutputList());
    getTaskConfig().setDriverStrategy(DriverStrategy.HYBRIDHASH_BUILD_SECOND);
    getTaskConfig().setMemoryDriver(HASH_MEM);

    final MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    final AtomicBoolean success = new AtomicBoolean(false);

    Thread taskRunner =
        new Thread() {
          @Override
          public void run() {
            try {
              testDriver(testTask, MockMatchStub.class);
              success.set(true);
            } catch (Exception ie) {
              ie.printStackTrace();
            }
          }
        };
    taskRunner.start();

    TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
    tct.start();

    try {
      tct.join();
      taskRunner.join();
    } catch (InterruptedException ie) {
      Assert.fail("Joining threads failed");
    }

    Assert.assertTrue(
        "Test threw an exception even though it was properly canceled.", success.get());
  }
Exemplo n.º 6
0
  @Test
  public void testSortBoth5MatchTask() {

    int keyCnt1 = 20;
    int valCnt1 = 20;

    int keyCnt2 = 20;
    int valCnt2 = 20;

    setOutput(this.outList);
    addInputComparator(this.comparator1);
    addInputComparator(this.comparator2);
    getTaskConfig().setDriverPairComparator(PactRecordPairComparatorFactory.get());
    getTaskConfig().setDriverStrategy(DriverStrategy.MERGE);
    getTaskConfig().setMemoryDriver(BNLJN_MEM);
    setNumFileHandlesForSort(4);

    final MatchDriver<PactRecord, PactRecord, PactRecord> testTask =
        new MatchDriver<PactRecord, PactRecord, PactRecord>();

    try {
      addInputSorted(
          new UniformPactRecordGenerator(keyCnt1, valCnt1, false), this.comparator1.duplicate());
      addInputSorted(
          new UniformPactRecordGenerator(keyCnt2, valCnt2, false), this.comparator2.duplicate());
      testDriver(testTask, MockMatchStub.class);
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("The test caused an exception.");
    }

    int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);

    Assert.assertTrue(
        "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
        this.outList.size() == expCnt);

    this.outList.clear();
  }