本文整理汇总了Java中org.easymock.Capture类的典型用法代码示例。如果您正苦于以下问题:Java Capture类的具体用法?Java Capture怎么用?Java Capture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Capture类属于org.easymock包,在下文中一共展示了Capture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdatePortStatus
import org.easymock.Capture; //导入依赖的package包/类
@Test
public final void testUpdatePortStatus() {
putDevice(DID1, SW1);
List<PortDescription> pds = Arrays.<PortDescription>asList(
new DefaultPortDescription(P1, true)
);
deviceStore.updatePorts(PID, DID1, pds);
Capture<InternalPortStatusEvent> message = new Capture<>();
Capture<MessageSubject> subject = new Capture<>();
Capture<Function<InternalPortStatusEvent, byte[]>> encoder = new Capture<>();
resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
final DefaultPortDescription desc = new DefaultPortDescription(P1, false);
DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, desc);
assertEquals(PORT_UPDATED, event.type());
assertDevice(DID1, SW1, event.subject());
assertEquals(P1, event.port().number());
assertFalse("Port is disabled", event.port().isEnabled());
verify(clusterCommunicator);
assertInternalPortStatusEvent(NID1, DID1, PID, desc, NO_ANNOTATION, message, subject, encoder);
assertTrue(message.hasCaptured());
}
示例2: testSendRecordsPropagatesTimestamp
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void testSendRecordsPropagatesTimestamp() throws Exception {
final Long timestamp = System.currentTimeMillis();
createWorkerTask();
List<SourceRecord> records = Collections.singletonList(
new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, timestamp)
);
Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();
PowerMock.replayAll();
Whitebox.setInternalState(workerTask, "toSend", records);
Whitebox.invokeMethod(workerTask, "sendRecords");
assertEquals(timestamp, sent.getValue().timestamp());
PowerMock.verifyAll();
}
示例3: testSendRecordsConvertsData
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void testSendRecordsConvertsData() throws Exception {
createWorkerTask();
List<SourceRecord> records = new ArrayList<>();
// Can just use the same record for key and value
records.add(new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD));
Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();
PowerMock.replayAll();
Whitebox.setInternalState(workerTask, "toSend", records);
Whitebox.invokeMethod(workerTask, "sendRecords");
assertEquals(SERIALIZED_KEY, sent.getValue().key());
assertEquals(SERIALIZED_RECORD, sent.getValue().value());
PowerMock.verifyAll();
}
示例4: testMessageWriteList
import org.easymock.Capture; //导入依赖的package包/类
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(ImmutableList.of(hello, packetOut));
assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(hello, packetOut));
}
示例5: testMessageWriteList
import org.easymock.Capture; //导入依赖的package包/类
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(ImmutableList.of(hello, packetOut));
eventLoop.runTasks();
assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(hello, packetOut));
}
示例6: shouldAcceptDefaultTimeWindow
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void shouldAcceptDefaultTimeWindow() {
final TwoWayChannelMessage message = createClientVersionMessage();
final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
connection.sendToClient(capture(initiateCapture));
replay(connection);
dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, connection);
dut.connectionOpen();
dut.receiveMessage(message);
long expectedExpire = Utils.currentTimeSeconds() + 24 * 60 * 60 - 60; // This the default defined in paymentchannel.proto
assertServerVersion();
assertExpireTime(expectedExpire, initiateCapture);
}
示例7: shouldAllowExactTimeWindow
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void shouldAllowExactTimeWindow() {
final TwoWayChannelMessage message = createClientVersionMessage();
final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
connection.sendToClient(capture(initiateCapture));
replay(connection);
final int expire = 24 * 60 * 60 - 60; // This the default defined in paymentchannel.proto
dut = new PaymentChannelServer(broadcaster, wallet, Coin.CENT, new PaymentChannelServer.DefaultServerChannelProperties(){
@Override
public long getMaxTimeWindow() { return expire; }
@Override
public long getMinTimeWindow() { return expire; }
}, connection);
dut.connectionOpen();
long expectedExpire = Utils.currentTimeSeconds() + expire;
dut.receiveMessage(message);
assertServerVersion();
assertExpireTime(expectedExpire, initiateCapture);
}
示例8: testSendRecordsCorruptTimestamp
import org.easymock.Capture; //导入依赖的package包/类
@Test(expected = InvalidRecordException.class)
public void testSendRecordsCorruptTimestamp() throws Exception {
final Long timestamp = -3L;
createWorkerTask();
List<SourceRecord> records = Collections.singletonList(
new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, timestamp)
);
Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();
PowerMock.replayAll();
Whitebox.setInternalState(workerTask, "toSend", records);
Whitebox.invokeMethod(workerTask, "sendRecords");
assertEquals(null, sent.getValue().timestamp());
PowerMock.verifyAll();
}
示例9: testSendRecordsNoTimestamp
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void testSendRecordsNoTimestamp() throws Exception {
final Long timestamp = -1L;
createWorkerTask();
List<SourceRecord> records = Collections.singletonList(
new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, timestamp)
);
Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();
PowerMock.replayAll();
Whitebox.setInternalState(workerTask, "toSend", records);
Whitebox.invokeMethod(workerTask, "sendRecords");
assertEquals(null, sent.getValue().timestamp());
PowerMock.verifyAll();
}
示例10: expectApplyTransformationChain
import org.easymock.Capture; //导入依赖的package包/类
private void expectApplyTransformationChain(boolean anyTimes) {
final Capture<SourceRecord> recordCapture = EasyMock.newCapture();
IExpectationSetters<SourceRecord> convertKeyExpect = EasyMock.expect(transformationChain.apply(EasyMock.capture(recordCapture)));
if (anyTimes)
convertKeyExpect.andStubAnswer(new IAnswer<SourceRecord>() {
@Override
public SourceRecord answer() {
return recordCapture.getValue();
}
});
else
convertKeyExpect.andAnswer(new IAnswer<SourceRecord>() {
@Override
public SourceRecord answer() {
return recordCapture.getValue();
}
});
}
示例11: testSchedule
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void testSchedule() throws Exception {
Capture<Runnable> taskWrapper = EasyMock.newCapture();
ScheduledFuture commitFuture = PowerMock.createMock(ScheduledFuture.class);
EasyMock.expect(executor.scheduleWithFixedDelay(
EasyMock.capture(taskWrapper), eq(DEFAULT_OFFSET_COMMIT_INTERVAL_MS),
eq(DEFAULT_OFFSET_COMMIT_INTERVAL_MS), eq(TimeUnit.MILLISECONDS))
).andReturn(commitFuture);
ConnectorTaskId taskId = PowerMock.createMock(ConnectorTaskId.class);
WorkerSourceTask task = PowerMock.createMock(WorkerSourceTask.class);
EasyMock.expect(committers.put(taskId, commitFuture)).andReturn(null);
PowerMock.replayAll();
committer.schedule(taskId, task);
assertTrue(taskWrapper.hasCaptured());
assertNotNull(taskWrapper.getValue());
PowerMock.verifyAll();
}
示例12: assertInternalDeviceEvent
import org.easymock.Capture; //导入依赖的package包/类
private void assertInternalDeviceEvent(NodeId sender,
DeviceId deviceId,
ProviderId providerId,
DeviceDescription expectedDesc,
Capture<InternalDeviceEvent> actualEvent,
Capture<MessageSubject> actualSubject,
Capture<Function<InternalDeviceEvent, byte[]>> actualEncoder) {
assertTrue(actualEvent.hasCaptured());
assertTrue(actualSubject.hasCaptured());
assertTrue(actualEncoder.hasCaptured());
assertEquals(GossipDeviceStoreMessageSubjects.DEVICE_UPDATE,
actualSubject.getValue());
assertEquals(deviceId, actualEvent.getValue().deviceId());
assertEquals(providerId, actualEvent.getValue().providerId());
assertDeviceDescriptionEquals(expectedDesc, actualEvent.getValue().deviceDescription().value());
}
示例13: testSingleMessageWrite
import org.easymock.Capture; //导入依赖的package包/类
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(packetOut);
assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(packetOut));
}
示例14: expectConvertWriteRead
import org.easymock.Capture; //导入依赖的package包/类
private void expectConvertWriteRead(final String configKey, final Schema valueSchema, final byte[] serialized,
final String dataFieldName, final Object dataFieldValue) {
final Capture<Struct> capturedRecord = EasyMock.newCapture();
if (serialized != null)
EasyMock.expect(converter.fromConnectData(EasyMock.eq(TOPIC), EasyMock.eq(valueSchema), EasyMock.capture(capturedRecord)))
.andReturn(serialized);
storeLog.send(EasyMock.eq(configKey), EasyMock.aryEq(serialized));
PowerMock.expectLastCall();
EasyMock.expect(converter.toConnectData(EasyMock.eq(TOPIC), EasyMock.aryEq(serialized)))
.andAnswer(new IAnswer<SchemaAndValue>() {
@Override
public SchemaAndValue answer() throws Throwable {
if (dataFieldName != null)
assertEquals(dataFieldValue, capturedRecord.getValue().get(dataFieldName));
// Note null schema because default settings for internal serialization are schema-less
return new SchemaAndValue(null, serialized == null ? null : structToMap(capturedRecord.getValue()));
}
});
}
示例15: testRestartConnectorOwnerRedirect
import org.easymock.Capture; //导入依赖的package包/类
@Test
public void testRestartConnectorOwnerRedirect() throws Throwable {
final Capture<Callback<Void>> cb = Capture.newInstance();
herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
String ownerUrl = "http://owner:8083";
expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));
EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/restart?forward=false"),
EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
.andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));
PowerMock.replayAll();
connectorsResource.restartConnector(CONNECTOR_NAME, true);
PowerMock.verifyAll();
}