當前位置: 首頁>>代碼示例>>Java>>正文


Java EasyMock.expect方法代碼示例

本文整理匯總了Java中org.easymock.EasyMock.expect方法的典型用法代碼示例。如果您正苦於以下問題:Java EasyMock.expect方法的具體用法?Java EasyMock.expect怎麽用?Java EasyMock.expect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.easymock.EasyMock的用法示例。


在下文中一共展示了EasyMock.expect方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: expectApplyTransformationChain

import org.easymock.EasyMock; //導入方法依賴的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();
            }
        });
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:19,代碼來源:WorkerSourceTaskTest.java

示例2: expectOffsetFlush

import org.easymock.EasyMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void expectOffsetFlush(boolean succeed) throws Exception {
    EasyMock.expect(offsetWriter.beginFlush()).andReturn(true);
    Future<Void> flushFuture = PowerMock.createMock(Future.class);
    EasyMock.expect(offsetWriter.doFlush(EasyMock.anyObject(Callback.class))).andReturn(flushFuture);
    // Should throw for failure
    IExpectationSetters<Void> futureGetExpect = EasyMock.expect(
            flushFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class)));
    if (succeed) {
        sourceTask.commit();
        EasyMock.expectLastCall();
        futureGetExpect.andReturn(null);
    } else {
        futureGetExpect.andThrow(new TimeoutException());
        offsetWriter.cancelFlush();
        PowerMock.expectLastCall();
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:19,代碼來源:WorkerSourceTaskTest.java

示例3: expectConvertKeyValue

import org.easymock.EasyMock; //導入方法依賴的package包/類
private void expectConvertKeyValue(boolean anyTimes) {
    IExpectationSetters<byte[]> convertKeyExpect = EasyMock.expect(keyConverter.fromConnectData(TOPIC, KEY_SCHEMA, KEY));
    if (anyTimes)
        convertKeyExpect.andStubReturn(SERIALIZED_KEY);
    else
        convertKeyExpect.andReturn(SERIALIZED_KEY);
    IExpectationSetters<byte[]> convertValueExpect = EasyMock.expect(valueConverter.fromConnectData(TOPIC, RECORD_SCHEMA, RECORD));
    if (anyTimes)
        convertValueExpect.andStubReturn(SERIALIZED_RECORD);
    else
        convertValueExpect.andReturn(SERIALIZED_RECORD);
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:13,代碼來源:WorkerSourceTaskTest.java

示例4: expectSendRecord

import org.easymock.EasyMock; //導入方法依賴的package包/類
private Capture<ProducerRecord<byte[], byte[]>> expectSendRecord(boolean anyTimes, boolean isRetry, boolean succeed) throws InterruptedException {
    expectConvertKeyValue(anyTimes);
    expectApplyTransformationChain(anyTimes);

    Capture<ProducerRecord<byte[], byte[]>> sent = EasyMock.newCapture();

    // 1. Offset data is passed to the offset storage.
    if (!isRetry) {
        offsetWriter.offset(PARTITION, OFFSET);
        if (anyTimes)
            PowerMock.expectLastCall().anyTimes();
        else
            PowerMock.expectLastCall();
    }

    // 2. Converted data passed to the producer, which will need callbacks invoked for flush to work
    IExpectationSetters<Future<RecordMetadata>> expect = EasyMock.expect(
            producer.send(EasyMock.capture(sent),
                    EasyMock.capture(producerCallbacks)));
    IAnswer<Future<RecordMetadata>> expectResponse = new IAnswer<Future<RecordMetadata>>() {
        @Override
        public Future<RecordMetadata> answer() throws Throwable {
            synchronized (producerCallbacks) {
                for (org.apache.kafka.clients.producer.Callback cb : producerCallbacks.getValues()) {
                    cb.onCompletion(new RecordMetadata(new TopicPartition("foo", 0), 0, 0,
                                                       0L, 0L, 0, 0), null);
                }
                producerCallbacks.reset();
            }
            return sendFuture;
        }
    };
    if (anyTimes)
        expect.andStubAnswer(expectResponse);
    else
        expect.andAnswer(expectResponse);

    // 3. As a result of a successful producer send callback, we'll notify the source task of the record commit
    expectTaskCommitRecord(anyTimes, succeed);

    return sent;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:43,代碼來源:WorkerSourceTaskTest.java


注:本文中的org.easymock.EasyMock.expect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。