@Before
  public void setUp() throws Exception {
    props = EasyMock.createStrictMock(Props.class);
    mockFlow1 = EasyMock.createMock(ExecutableFlow.class);
    mockFlow2 = EasyMock.createMock(ExecutableFlow.class);

    EasyMock.expect(mockFlow1.getName()).andReturn("a").once();
    EasyMock.expect(mockFlow2.getName()).andReturn("b").once();

    EasyMock.expect(mockFlow1.getStatus()).andReturn(Status.READY).times(3);
    EasyMock.expect(mockFlow2.getStatus()).andReturn(Status.READY).times(3);

    EasyMock.expect(mockFlow1.getStartTime()).andReturn(null).once();
    EasyMock.expect(mockFlow2.getStartTime()).andReturn(null).once();

    EasyMock.expect(mockFlow1.getName()).andReturn("1").once();
    EasyMock.expect(mockFlow2.getName()).andReturn("2").once();
    EasyMock.replay(mockFlow1, mockFlow2, props);

    flow = new GroupedExecutableFlow("blah", mockFlow1, mockFlow2);
    Assert.assertEquals("1 + 2", flow.getName());

    EasyMock.verify(mockFlow1, mockFlow2, props);
    EasyMock.reset(mockFlow1, mockFlow2, props);
  }
 @Before
 public void setUp() {
   this.processManager = EasyMock.createMock(ProcessManager.class);
   this.osInfo = org.easymock.classextension.EasyMock.createMock(OperatingSystem.class);
   this.embeddedDBController =
       new PostgresEmbeddedDatabaseController(serverHome, processManager, osInfo);
 }
  /** tests {@link MostSimilarItemPairsMapper} */
  public void testMostSimilarItemsPairsMapper() throws Exception {

    OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap();
    indexItemIDMap.put(12, 12L);
    indexItemIDMap.put(34, 34L);
    indexItemIDMap.put(56, 56L);

    Mapper<IntWritable, VectorWritable, EntityEntityWritable, DoubleWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(new EntityEntityWritable(34L, 56L), new DoubleWritable(0.9));

    EasyMock.replay(context);

    Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE);
    vector.set(12, 0.2);
    vector.set(34, 1.0);
    vector.set(56, 0.9);

    MostSimilarItemPairsMapper mapper = new MostSimilarItemPairsMapper();
    setField(mapper, "indexItemIDMap", indexItemIDMap);
    setField(mapper, "maxSimilarItemsPerItem", 1);

    mapper.map(new IntWritable(34), new VectorWritable(vector), context);

    EasyMock.verify(context);
  }
  /**
   * Tests that the filter just passes objects which aren't FileRegion's through to the next filter.
   *
   * @throws Exception when something goes wrong
   */
  @Test
  public void testWriteNonFileRegionMessage() throws Exception {
    AbstractStreamWriteFilter<M> filter = createFilter();

    Object message = new Object();
    WriteRequest writeRequest = new DefaultWriteRequest(message, new DummyWriteFuture());

    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    /*
     * Record expectations
     */
    nextFilter.filterWrite(session, writeRequest);
    nextFilter.messageSent(session, writeRequest);

    /*
     * Replay.
     */
    EasyMock.replay(nextFilter);

    filter.filterWrite(nextFilter, session, writeRequest);
    filter.messageSent(nextFilter, session, writeRequest);

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);
  }
  @Test
  public void testBasic() throws Exception {
    ServiceHandler handler = new ServiceHandler();
    Service service = new Service();
    handler.registerWebService(service);

    Request baseRequest = org.easymock.classextension.EasyMock.createMock(Request.class);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpServletResponse response = createMock(HttpServletResponse.class);

    expect(baseRequest.isHandled()).andReturn(false);
    expect(request.getMethod()).andReturn("GET");
    expect(request.getPathInfo()).andReturn("/");
    expect(request.getParameter("bar")).andReturn("bar2");
    expect(request.getParameter("baz")).andReturn(null);
    expect(request.getHeader("Content-Length")).andReturn("103");
    expect(response.isCommitted()).andReturn(false).anyTimes();
    baseRequest.setHandled(true);

    org.easymock.classextension.EasyMock.replay(baseRequest);
    replay(request, response);
    handler.handle(null, baseRequest, request, response);
    org.easymock.classextension.EasyMock.verify(baseRequest);
    verify(request, response);
  }
Beispiel #6
0
  /** tests {@link ToVectorAndPrefReducer} */
  @Test
  public void testToVectorAndPrefReducer() throws Exception {
    Reducer<VarIntWritable, VectorOrPrefWritable, VarIntWritable, VectorAndPrefsWritable>.Context
        context = EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarIntWritable(1)),
        vectorAndPrefsWritableMatches(
            Arrays.asList(123L, 456L),
            Arrays.asList(1.0f, 2.0f),
            MathHelper.elem(3, 0.5),
            MathHelper.elem(7, 0.8)));

    EasyMock.replay(context);

    Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumn.set(3, 0.5);
    similarityColumn.set(7, 0.8);

    VectorOrPrefWritable itemPref1 = new VectorOrPrefWritable(123L, 1.0f);
    VectorOrPrefWritable itemPref2 = new VectorOrPrefWritable(456L, 2.0f);
    VectorOrPrefWritable similarities = new VectorOrPrefWritable(similarityColumn);

    new ToVectorAndPrefReducer()
        .reduce(new VarIntWritable(1), Arrays.asList(itemPref1, itemPref2, similarities), context);

    EasyMock.verify(context);
  }
Beispiel #7
0
  public void getPeerStatusChangeHistory(
      DiscoveryServiceComponent component, List<DS_PeerStatusChange> historyList) {

    CommunityStatusProvider communityStatusProvider = getCommunityStatusProviders(component);
    ObjectDeployment cspObjectDeployment = getCommunityStatusProvidersObjectDeployment(component);

    CommunityStatusProviderClient cspClientMock =
        EasyMock.createMock(CommunityStatusProviderClient.class);

    // adding behavior
    cspClientMock.hereIsPeerStatusChangeHistory(
        DS_PeerStatusChangeHistoryMatcher.eqMatcher((historyList)), EasyMock.gt(0L));

    EasyMock.replay(cspClientMock);

    DeploymentID deploymentID =
        new DeploymentID(new ContainerID("dsClient", "dsServer", "peer", "dsClientPK"), "peer");
    AcceptanceTestUtil.publishTestObject(
        component, deploymentID, cspClientMock, CommunityStatusProviderClient.class);

    AcceptanceTestUtil.setExecutionContext(component, cspObjectDeployment, deploymentID);

    communityStatusProvider.getPeerStatusChangeHistory(cspClientMock, 0L);

    EasyMock.verify(cspClientMock);
  }
  @Test(expected = Exception.class)
  public void testResolveDirectoryBeforeTimeout() throws LBInvocationException {
    LexBIGService lbs = EasyMock.createMock(LexBIGService.class);

    CodingSchemeRenderingList csrl = new CodingSchemeRenderingList();
    CodingSchemeRendering csr = new TimeoutCodingSchemeRendering();

    csrl.addCodingSchemeRendering(csr);

    EasyMock.expect(lbs.getSupportedCodingSchemes()).andReturn(csrl).anyTimes();
    EasyMock.replay(lbs);

    lexEvsCodeSystemVersionQuery.setLexBigService(lbs);
    codeSystemVersonDirectoryURIFactory.setLexBigService(lbs);

    CodeSystemVersionDirectoryURI directoryUri =
        lexEvsCodeSystemVersionQuery.getCodeSystemVersions();

    QueryControl queryControl = new QueryControl();
    queryControl.setTimeLimit(600l);

    CodeSystemVersionDirectory directory =
        lexEvsCodeSystemVersionQuery.resolve(directoryUri, queryControl, null);

    assertNotNull(directory);
  }
Beispiel #9
0
  /** tests {@link PartialMultiplyMapper} */
  @Test
  public void testPartialMultiplyMapper() throws Exception {

    Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumn.set(3, 0.5);
    similarityColumn.set(7, 0.8);

    Mapper<VarIntWritable, VectorAndPrefsWritable, VarLongWritable, PrefAndSimilarityColumnWritable>
            .Context
        context = EasyMock.createMock(Mapper.Context.class);

    PrefAndSimilarityColumnWritable one = new PrefAndSimilarityColumnWritable();
    PrefAndSimilarityColumnWritable two = new PrefAndSimilarityColumnWritable();
    one.set(1.0f, similarityColumn);
    two.set(3.0f, similarityColumn);

    context.write(EasyMock.eq(new VarLongWritable(123L)), EasyMock.eq(one));
    context.write(EasyMock.eq(new VarLongWritable(456L)), EasyMock.eq(two));

    EasyMock.replay(context);

    VectorAndPrefsWritable vectorAndPrefs =
        new VectorAndPrefsWritable(
            similarityColumn, Arrays.asList(123L, 456L), Arrays.asList(1.0f, 3.0f));

    new PartialMultiplyMapper().map(new VarIntWritable(1), vectorAndPrefs, context);

    EasyMock.verify(context);
  }
  @Test
  public void testWriteEmptyFile() throws Exception {
    AbstractStreamWriteFilter<M> filter = createFilter();
    M message = createMessage(new byte[0]);

    WriteRequest writeRequest = new DefaultWriteRequest(message, new DummyWriteFuture());

    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    /*
     * Record expectations
     */
    nextFilter.messageSent(session, writeRequest);

    /*
     * Replay.
     */
    EasyMock.replay(nextFilter);

    filter.filterWrite(nextFilter, session, writeRequest);

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);

    assertTrue(writeRequest.getFuture().isWritten());
  }
  @Test
  public void testWriteWhileWriteInProgress() throws Exception {
    AbstractStreamWriteFilter<M> filter = createFilter();
    M message = createMessage(new byte[5]);

    Queue<WriteRequest> queue = new LinkedList<WriteRequest>();

    /*
     * Make up the situation.
     */
    session.setAttribute(filter.CURRENT_STREAM, message);
    session.setAttribute(filter.WRITE_REQUEST_QUEUE, queue);

    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    /*
     * Replay.  (We recorded *nothing* because nothing should occur.)
     */
    EasyMock.replay(nextFilter);

    WriteRequest wr = new DefaultWriteRequest(new Object(), new DummyWriteFuture());
    filter.filterWrite(nextFilter, session, wr);
    assertEquals(1, queue.size());
    assertSame(wr, queue.poll());

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);

    session.removeAttribute(filter.CURRENT_STREAM);
    session.removeAttribute(filter.WRITE_REQUEST_QUEUE);
  }
  /**
   * Tests when the contents of the file fits into one write buffer.
   *
   * @throws Exception when something goes wrong
   */
  @Test
  public void testWriteSingleBufferFile() throws Exception {
    byte[] data = new byte[] {1, 2, 3, 4};

    AbstractStreamWriteFilter<M> filter = createFilter();
    M message = createMessage(data);

    WriteRequest writeRequest = new DefaultWriteRequest(message, new DummyWriteFuture());

    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    /*
     * Record expectations
     */
    nextFilter.filterWrite(
        EasyMock.eq(session), eqWriteRequest(new DefaultWriteRequest(IoBuffer.wrap(data))));
    nextFilter.messageSent(session, writeRequest);

    /*
     * Replay.
     */
    EasyMock.replay(nextFilter);

    filter.filterWrite(nextFilter, session, writeRequest);
    filter.messageSent(nextFilter, session, writeRequest);

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);

    assertTrue(writeRequest.getFuture().isWritten());
  }
Beispiel #13
0
  /**
   * tests {@link UserVectorSplitterMapper} in the special case that some userIDs shall be excluded
   */
  @Test
  public void testUserVectorSplitterMapperUserExclusion() throws Exception {
    Mapper<VarLongWritable, VectorWritable, VarIntWritable, VectorOrPrefWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(
        EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f));
    context.write(
        EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f));

    EasyMock.replay(context);

    FastIDSet usersToRecommendFor = new FastIDSet();
    usersToRecommendFor.add(123L);

    UserVectorSplitterMapper mapper = new UserVectorSplitterMapper();
    setField(mapper, "maxPrefsPerUserConsidered", 10);
    setField(mapper, "usersToRecommendFor", usersToRecommendFor);

    RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    vector.set(34, 0.5);
    vector.set(56, 0.7);

    mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context);
    mapper.map(new VarLongWritable(456L), new VectorWritable(vector), context);

    EasyMock.verify(context);
  }
 @Test
 public void rollbackShouldRollback() {
   GeonamesAdm3Importer geonamesAdm3Importer = new GeonamesAdm3Importer();
   IAdmDao admDao = EasyMock.createMock(IAdmDao.class);
   EasyMock.expect(admDao.deleteAllByLevel(3)).andReturn(4);
   EasyMock.replay(admDao);
   geonamesAdm3Importer.setAdmDao(admDao);
   List<NameValueDTO<Integer>> deleted = geonamesAdm3Importer.rollback();
   assertEquals(1, deleted.size());
   assertEquals(4, deleted.get(0).getValue().intValue());
 }
Beispiel #15
0
  /** tests {@link ItemIDIndexMapper} */
  @Test
  public void testItemIDIndexMapper() throws Exception {
    Mapper<LongWritable, Text, VarIntWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(new VarIntWritable(TasteHadoopUtils.idToIndex(789L)), new VarLongWritable(789L));
    EasyMock.replay(context);

    new ItemIDIndexMapper().map(new LongWritable(123L), new Text("456,789,5.0"), context);

    EasyMock.verify(context);
  }
  /** tests {@link CountUsersMapper} */
  public void testCountUsersMapper() throws Exception {
    Mapper<LongWritable, Text, CountUsersKeyWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);
    context.write(keyForUserID(12L), EasyMock.eq(new VarLongWritable(12L)));
    context.write(keyForUserID(35L), EasyMock.eq(new VarLongWritable(35L)));
    EasyMock.replay(context);

    CountUsersMapper mapper = new CountUsersMapper();
    mapper.map(null, new Text("12,100,1.3"), context);
    mapper.map(null, new Text("35,100,3.0"), context);

    EasyMock.verify(context);
  }
Beispiel #17
0
  /** tests {@link ToItemPrefsMapper} */
  @Test
  public void testToItemPrefsMapper() throws Exception {
    Mapper<LongWritable, Text, VarLongWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(new VarLongWritable(12L), new EntityPrefWritable(34L, 1.0f));
    context.write(new VarLongWritable(56L), new EntityPrefWritable(78L, 2.0f));
    EasyMock.replay(context);

    ToItemPrefsMapper mapper = new ToItemPrefsMapper();
    mapper.map(new LongWritable(123L), new Text("12,34,1"), context);
    mapper.map(new LongWritable(456L), new Text("56,78,2"), context);

    EasyMock.verify(context);
  }
  /** tests {@link CountUsersReducer} */
  public void testCountUsersReducer() throws Exception {
    Reducer<CountUsersKeyWritable, VarLongWritable, VarIntWritable, NullWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);
    context.write(new VarIntWritable(3), NullWritable.get());
    EasyMock.replay(context);

    List<VarLongWritable> userIDs =
        Arrays.asList(
            new VarLongWritable(1L), new VarLongWritable(1L),
            new VarLongWritable(3L), new VarLongWritable(5L),
            new VarLongWritable(5L), new VarLongWritable(5L));

    new CountUsersReducer().reduce(null, userIDs, context);
    EasyMock.verify(context);
  }
Beispiel #19
0
  /** tests {@link ToItemPrefsMapper} using boolean data */
  @Test
  public void testToItemPrefsMapperBooleanData() throws Exception {
    Mapper<LongWritable, Text, VarLongWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(new VarLongWritable(12L), new VarLongWritable(34L));
    context.write(new VarLongWritable(56L), new VarLongWritable(78L));
    EasyMock.replay(context);

    ToItemPrefsMapper mapper = new ToItemPrefsMapper();
    setField(mapper, "booleanData", true);
    mapper.map(new LongWritable(123L), new Text("12,34"), context);
    mapper.map(new LongWritable(456L), new Text("56,78"), context);

    EasyMock.verify(context);
  }
  /** tests {@link MostSimilarItemPairsReducer} */
  public void testMostSimilarItemPairsReducer() throws Exception {
    Reducer<EntityEntityWritable, DoubleWritable, EntityEntityWritable, DoubleWritable>.Context
        context = EasyMock.createMock(Reducer.Context.class);

    context.write(new EntityEntityWritable(123L, 456L), new DoubleWritable(0.5));

    EasyMock.replay(context);

    new MostSimilarItemPairsReducer()
        .reduce(
            new EntityEntityWritable(123L, 456L),
            Arrays.asList(new DoubleWritable(0.5), new DoubleWritable(0.5)),
            context);

    EasyMock.verify(context);
  }
Beispiel #21
0
  /** tests {@link ItemIDIndexReducer} */
  @Test
  public void testItemIDIndexReducer() throws Exception {
    Reducer<VarIntWritable, VarLongWritable, VarIntWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(new VarIntWritable(123), new VarLongWritable(45L));
    EasyMock.replay(context);

    new ItemIDIndexReducer()
        .reduce(
            new VarIntWritable(123),
            Arrays.asList(
                new VarLongWritable(67L), new VarLongWritable(89L), new VarLongWritable(45L)),
            context);

    EasyMock.verify(context);
  }
Beispiel #22
0
  /** tests {@link org.apache.mahout.cf.taste.hadoop.item.ItemFilterMapper} */
  @Test
  public void testItemFilterMapper() throws Exception {

    Mapper<LongWritable, Text, VarLongWritable, VarLongWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(new VarLongWritable(34L), new VarLongWritable(12L));
    context.write(new VarLongWritable(78L), new VarLongWritable(56L));

    EasyMock.replay(context);

    ItemFilterMapper mapper = new ItemFilterMapper();
    mapper.map(null, new Text("12,34"), context);
    mapper.map(null, new Text("56,78"), context);

    EasyMock.verify(context);
  }
Beispiel #23
0
  /** tests {@link AggregateAndRecommendReducer} */
  @Test
  public void testAggregateAndRecommendReducer() throws Exception {
    Reducer<
                VarLongWritable,
                PrefAndSimilarityColumnWritable,
                VarLongWritable,
                RecommendedItemsWritable>
            .Context
        context = EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarLongWritable(123L)),
        recommendationsMatch(
            new GenericRecommendedItem(1L, 2.8f), new GenericRecommendedItem(2L, 2.0f)));

    EasyMock.replay(context);

    RandomAccessSparseVector similarityColumnOne =
        new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnOne.set(1, 0.1);
    similarityColumnOne.set(2, 0.5);

    RandomAccessSparseVector similarityColumnTwo =
        new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    similarityColumnTwo.set(1, 0.9);
    similarityColumnTwo.set(2, 0.5);

    List<PrefAndSimilarityColumnWritable> values =
        Arrays.asList(
            new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne),
            new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo));

    OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap();
    indexItemIDMap.put(1, 1L);
    indexItemIDMap.put(2, 2L);

    AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer();

    setField(reducer, "indexItemIDMap", indexItemIDMap);
    setField(reducer, "recommendationsPerUser", 3);

    reducer.reduce(new VarLongWritable(123L), values, context);

    EasyMock.verify(context);
  }
  @Test
  public void testWritesWriteRequestQueueWhenFinished() throws Exception {
    AbstractStreamWriteFilter<M> filter = createFilter();
    M message = createMessage(new byte[0]);

    WriteRequest wrs[] =
        new WriteRequest[] {
          new DefaultWriteRequest(new Object(), new DummyWriteFuture()),
          new DefaultWriteRequest(new Object(), new DummyWriteFuture()),
          new DefaultWriteRequest(new Object(), new DummyWriteFuture())
        };
    Queue<WriteRequest> queue = new LinkedList<WriteRequest>();
    queue.add(wrs[0]);
    queue.add(wrs[1]);
    queue.add(wrs[2]);

    /*
     * Make up the situation.
     */
    session.setAttribute(filter.CURRENT_STREAM, message);
    session.setAttribute(filter.CURRENT_WRITE_REQUEST, new DefaultWriteRequest(message));
    session.setAttribute(filter.WRITE_REQUEST_QUEUE, queue);

    /*
     * Record expectations
     */
    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    nextFilter.filterWrite(session, wrs[0]);
    nextFilter.filterWrite(session, wrs[1]);
    nextFilter.filterWrite(session, wrs[2]);
    nextFilter.messageSent(EasyMock.eq(session), eqWriteRequest(new DefaultWriteRequest(message)));

    /*
     * Replay.
     */
    EasyMock.replay(nextFilter);

    filter.messageSent(nextFilter, session, new DefaultWriteRequest(new Object()));
    assertEquals(0, queue.size());

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);
  }
  /**
   * Tests when the contents of the file doesn't fit into one write buffer.
   *
   * @throws Exception when something goes wrong
   */
  @Test
  public void testWriteSeveralBuffersStream() throws Exception {
    AbstractStreamWriteFilter<M> filter = createFilter();
    filter.setWriteBufferSize(4);

    byte[] data = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    byte[] chunk1 = new byte[] {1, 2, 3, 4};
    byte[] chunk2 = new byte[] {5, 6, 7, 8};
    byte[] chunk3 = new byte[] {9, 10};

    M message = createMessage(data);
    WriteRequest writeRequest = new DefaultWriteRequest(message, new DummyWriteFuture());

    WriteRequest chunk1Request = new DefaultWriteRequest(IoBuffer.wrap(chunk1));
    WriteRequest chunk2Request = new DefaultWriteRequest(IoBuffer.wrap(chunk2));
    WriteRequest chunk3Request = new DefaultWriteRequest(IoBuffer.wrap(chunk3));

    NextFilter nextFilter = EasyMock.createMock(NextFilter.class);
    /*
     * Record expectations
     */
    nextFilter.filterWrite(EasyMock.eq(session), eqWriteRequest(chunk1Request));
    nextFilter.filterWrite(EasyMock.eq(session), eqWriteRequest(chunk2Request));
    nextFilter.filterWrite(EasyMock.eq(session), eqWriteRequest(chunk3Request));
    nextFilter.messageSent(EasyMock.eq(session), eqWriteRequest(writeRequest));

    /*
     * Replay.
     */
    EasyMock.replay(nextFilter);

    filter.filterWrite(nextFilter, session, writeRequest);
    filter.messageSent(nextFilter, session, chunk1Request);
    filter.messageSent(nextFilter, session, chunk2Request);
    filter.messageSent(nextFilter, session, chunk3Request);

    /*
     * Verify.
     */
    EasyMock.verify(nextFilter);

    assertTrue(writeRequest.getFuture().isWritten());
  }
Beispiel #26
0
  /** tests {@link org.apache.mahout.cf.taste.hadoop.item.ItemFilterAsVectorAndPrefsReducer} */
  @Test
  public void testItemFilterAsVectorAndPrefsReducer() throws Exception {
    Reducer<VarLongWritable, VarLongWritable, VarIntWritable, VectorAndPrefsWritable>.Context
        context = EasyMock.createMock(Reducer.Context.class);

    int itemIDIndex = TasteHadoopUtils.idToIndex(123L);
    context.write(
        EasyMock.eq(new VarIntWritable(itemIDIndex)),
        vectorAndPrefsForFilteringMatches(123L, 456L, 789L));

    EasyMock.replay(context);

    new ItemFilterAsVectorAndPrefsReducer()
        .reduce(
            new VarLongWritable(123L),
            Arrays.asList(new VarLongWritable(456L), new VarLongWritable(789L)),
            context);

    EasyMock.verify(context);
  }
Beispiel #27
0
  /** tests {@link ToUserVectorReducer} */
  @Test
  public void testToUserVectorReducer() throws Exception {
    Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarLongWritable(12L)),
        MathHelper.vectorMatches(
            MathHelper.elem(TasteHadoopUtils.idToIndex(34L), 1.0),
            MathHelper.elem(TasteHadoopUtils.idToIndex(56L), 2.0)));

    EasyMock.replay(context);

    Collection<VarLongWritable> varLongWritables = new LinkedList<VarLongWritable>();
    varLongWritables.add(new EntityPrefWritable(34L, 1.0f));
    varLongWritables.add(new EntityPrefWritable(56L, 2.0f));

    new ToUserVectorReducer().reduce(new VarLongWritable(12L), varLongWritables, context);

    EasyMock.verify(context);
  }
Beispiel #28
0
  /** tests {@link SimilarityMatrixRowWrapperMapper} */
  @Test
  public void testSimilarityMatrixRowWrapperMapper() throws Exception {
    Mapper<IntWritable, VectorWritable, VarIntWritable, VectorOrPrefWritable>.Context context =
        EasyMock.createMock(Mapper.Context.class);

    context.write(
        EasyMock.eq(new VarIntWritable(12)),
        vectorOfVectorOrPrefWritableMatches(MathHelper.elem(34, 0.5), MathHelper.elem(56, 0.7)));

    EasyMock.replay(context);

    RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    vector.set(12, 1.0);
    vector.set(34, 0.5);
    vector.set(56, 0.7);

    new SimilarityMatrixRowWrapperMapper()
        .map(new IntWritable(12), new VectorWritable(vector), context);

    EasyMock.verify(context);
  }
Beispiel #29
0
  /** tests {@link ToUserVectorReducer} using boolean data */
  @Test
  public void testToUserVectorReducerWithBooleanData() throws Exception {
    Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable>.Context context =
        EasyMock.createMock(Reducer.Context.class);

    context.write(
        EasyMock.eq(new VarLongWritable(12L)),
        MathHelper.vectorMatches(
            MathHelper.elem(TasteHadoopUtils.idToIndex(34L), 1.0),
            MathHelper.elem(TasteHadoopUtils.idToIndex(56L), 1.0)));

    EasyMock.replay(context);

    new ToUserVectorReducer()
        .reduce(
            new VarLongWritable(12L),
            Arrays.asList(new VarLongWritable(34L), new VarLongWritable(56L)),
            context);

    EasyMock.verify(context);
  }
Beispiel #30
0
  /**
   * tests {@link ToVectorAndPrefReducer} in the error case that two similarity column vectors a
   * supplied for the same item (which should never happen)
   */
  @Test
  public void testToVectorAndPrefReducerExceptionOn2Vectors() throws Exception {
    Reducer<VarIntWritable, VectorOrPrefWritable, VarIntWritable, VectorAndPrefsWritable>.Context
        context = EasyMock.createMock(Reducer.Context.class);

    EasyMock.replay(context);

    Vector similarityColumn1 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    Vector similarityColumn2 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);

    VectorOrPrefWritable similarities1 = new VectorOrPrefWritable(similarityColumn1);
    VectorOrPrefWritable similarities2 = new VectorOrPrefWritable(similarityColumn2);

    try {
      new ToVectorAndPrefReducer()
          .reduce(new VarIntWritable(1), Arrays.asList(similarities1, similarities2), context);
      fail();
    } catch (IllegalStateException e) {
      // good
    }

    EasyMock.verify(context);
  }