Java Code Examples for org.easymock.Capture.getValues()

The following are Jave code examples for showing how to use getValues() of the org.easymock.Capture class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kafka-0.11.0.0-src-with-comment   File: WorkerSinkTaskThreadedTest.java   View Source Code Vote up 5 votes
@Test
public void testPollsInBackground() throws Exception {
    expectInitializeTask();
    expectPollInitialAssignment();

    Capture<Collection<SinkRecord>> capturedRecords = expectPolls(1L);
    expectStopTask();

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();

    // First iteration initializes partition assignment
    workerTask.iteration();

    // Then we iterate to fetch data
    for (int i = 0; i < 10; i++) {
        workerTask.iteration();
    }
    workerTask.stop();
    workerTask.close();

    // Verify contents match expected values, i.e. that they were translated properly. With max
    // batch size 1 and poll returns 1 message at a time, we should have a matching # of batches
    assertEquals(10, capturedRecords.getValues().size());
    int offset = 0;
    for (Collection<SinkRecord> recs : capturedRecords.getValues()) {
        assertEquals(1, recs.size());
        for (SinkRecord rec : recs) {
            SinkRecord referenceSinkRecord
                    = new SinkRecord(TOPIC, PARTITION, KEY_SCHEMA, KEY, VALUE_SCHEMA, VALUE, FIRST_OFFSET + offset, TIMESTAMP, TIMESTAMP_TYPE);
            assertEquals(referenceSinkRecord, rec);
            offset++;
        }
    }

    PowerMock.verifyAll();
}
 
Example 2
Project: fresco_floodlight   File: LinkDiscoveryManagerTest.java   View Source Code Vote up 4 votes
@Test
public void testSwitchAdded() throws Exception {
    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
    linkDiscovery.switchService = getMockSwitchService();
    Capture<OFMessage> wc;
    Set<OFPort> qPorts;
    OFPortDesc ofpp = OFFactories.getFactory(OFVersion.OF_13).buildPortDesc()
    .setName("eth4242")
    .setPortNo(OFPort.of(4242))
    .setHwAddr(MacAddress.of("5c:16:c7:00:00:01"))
    .setCurr(new HashSet<OFPortFeatures>()) // random
    .build();
    IOFSwitch sw1 = createMockSwitch(1L);

    // Set switch map in floodlightProvider.
    Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
    switches.put(DatapathId.of(1L), sw1);
    getMockSwitchService().setSwitches(switches);

    // Create the set of ports
    List<OFPort> ports = new ArrayList<OFPort>();
    for(short p=1; p<=20; ++p) {
        ports.add(OFPort.of(p));
    }

    // Set the captures.
    wc = new Capture<OFMessage>(CaptureType.ALL);

    // Expect switch to return those ports.
    expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes();
    expect(sw1.getPort(OFPort.of(EasyMock.anyInt()))).andReturn(ofpp).anyTimes();
    expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    expect(sw1.getLatency()).andReturn(U64.ZERO).anyTimes();
    expect(sw1.write(capture(wc))).andReturn(true).anyTimes();
    replay(sw1);

    linkDiscovery.switchActivated(sw1.getId());
    verify(sw1);

    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(100);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(200);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertTrue(qPorts.isEmpty());

    // Ensure that through every switch port, an LLDP and BDDP
    // packet was sent out.  Total # of packets = # of ports * 2.
    assertTrue(wc.hasCaptured());
    List<OFMessage> msgList = wc.getValues();
    assertTrue(msgList.size() == ports.size() * 2);
}
 
Example 3
Project: iTAP-controller   File: LinkDiscoveryManagerTest.java   View Source Code Vote up 4 votes
@Test
public void testSwitchAdded() throws Exception {
    LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
    linkDiscovery.switchService = getMockSwitchService();
    Capture<OFMessage> wc;
    Set<OFPort> qPorts;
    OFPortDesc ofpp = OFFactories.getFactory(OFVersion.OF_13).buildPortDesc()
    .setName("eth4242")
    .setPortNo(OFPort.of(4242))
    .setHwAddr(MacAddress.of("5c:16:c7:00:00:01"))
    .setCurr(new HashSet<OFPortFeatures>()) // random
    .build();
    IOFSwitch sw1 = createMockSwitch(1L);

    // Set switch map in floodlightProvider.
    Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
    switches.put(DatapathId.of(1L), sw1);
    getMockSwitchService().setSwitches(switches);

    // Create the set of ports
    List<OFPort> ports = new ArrayList<OFPort>();
    for(short p=1; p<=20; ++p) {
        ports.add(OFPort.of(p));
    }

    // Set the captures.
    wc = new Capture<OFMessage>(CaptureType.ALL);

    // Expect switch to return those ports.
    expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes();
    expect(sw1.getPort(OFPort.of(EasyMock.anyInt()))).andReturn(ofpp).anyTimes();
    expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    sw1.write(capture(wc));
    expectLastCall().anyTimes();
    replay(sw1);

    linkDiscovery.switchActivated(sw1.getId());
    verify(sw1);

    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(100);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertFalse(qPorts.isEmpty());

    Thread.sleep(200);
    qPorts = linkDiscovery.getQuarantinedPorts(sw1.getId());
    assertNotNull(qPorts);
    assertTrue(qPorts.isEmpty());

    // Ensure that through every switch port, an LLDP and BDDP
    // packet was sent out.  Total # of packets = # of ports * 2.
    assertTrue(wc.hasCaptured());
    List<OFMessage> msgList = wc.getValues();
    assertTrue(msgList.size() == ports.size() * 2);
}