当前位置: 首页>>代码示例>>Java>>正文


Java IAnswer类代码示例

本文整理汇总了Java中org.easymock.IAnswer的典型用法代码示例。如果您正苦于以下问题:Java IAnswer类的具体用法?Java IAnswer怎么用?Java IAnswer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IAnswer类属于org.easymock包,在下文中一共展示了IAnswer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: expectPolls

import org.easymock.IAnswer; //导入依赖的package包/类
private CountDownLatch expectPolls(int minimum, final AtomicInteger count) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(minimum);
    // Note that we stub these to allow any number of calls because the thread will continue to
    // run. The count passed in + latch returned just makes sure we get *at least* that number of
    // calls
    EasyMock.expect(sourceTask.poll())
            .andStubAnswer(new IAnswer<List<SourceRecord>>() {
                @Override
                public List<SourceRecord> answer() throws Throwable {
                    count.incrementAndGet();
                    latch.countDown();
                    return RECORDS;
                }
            });
    // Fallout of the poll() call
    expectSendRecordAnyTimes();
    return latch;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:WorkerSourceTaskTest.java

示例2: expectApplyTransformationChain

import org.easymock.IAnswer; //导入依赖的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

示例3: expectRebalanceAssignmentError

import org.easymock.IAnswer; //导入依赖的package包/类
private void expectRebalanceAssignmentError(RuntimeException e) {
    final List<TopicPartition> partitions = asList(TOPIC_PARTITION, TOPIC_PARTITION2);

    sinkTask.close(new HashSet<>(partitions));
    EasyMock.expectLastCall();

    sinkTask.preCommit(EasyMock.<Map<TopicPartition, OffsetAndMetadata>>anyObject());
    EasyMock.expectLastCall().andReturn(Collections.emptyMap());

    EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);

    sinkTask.open(partitions);
    EasyMock.expectLastCall().andThrow(e);

    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
            new IAnswer<ConsumerRecords<byte[], byte[]>>() {
                @Override
                public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
                    rebalanceListener.getValue().onPartitionsRevoked(partitions);
                    rebalanceListener.getValue().onPartitionsAssigned(partitions);
                    return ConsumerRecords.empty();
                }
            });
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:WorkerSinkTaskTest.java

示例4: expectPollInitialAssignment

import org.easymock.IAnswer; //导入依赖的package包/类
private void expectPollInitialAssignment() {
    final List<TopicPartition> partitions = asList(TOPIC_PARTITION, TOPIC_PARTITION2);

    sinkTask.open(partitions);
    EasyMock.expectLastCall();

    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(new IAnswer<ConsumerRecords<byte[], byte[]>>() {
        @Override
        public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
            rebalanceListener.getValue().onPartitionsAssigned(partitions);
            return ConsumerRecords.empty();
        }
    });
    EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);

    sinkTask.put(Collections.<SinkRecord>emptyList());
    EasyMock.expectLastCall();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:WorkerSinkTaskTest.java

示例5: expectConsumerPoll

import org.easymock.IAnswer; //导入依赖的package包/类
private void expectConsumerPoll(final int numMessages, final long timestamp, final TimestampType timestampType) {
    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
            new IAnswer<ConsumerRecords<byte[], byte[]>>() {
                @Override
                public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
                    List<ConsumerRecord<byte[], byte[]>> records = new ArrayList<>();
                    for (int i = 0; i < numMessages; i++)
                        records.add(new ConsumerRecord<>(TOPIC, PARTITION, FIRST_OFFSET + recordsReturned + i, timestamp, timestampType, 0L, 0, 0, RAW_KEY, RAW_VALUE));
                    recordsReturned += numMessages;
                    return new ConsumerRecords<>(
                            numMessages > 0 ?
                                    Collections.singletonMap(new TopicPartition(TOPIC, PARTITION), records) :
                                    Collections.<TopicPartition, List<ConsumerRecord<byte[], byte[]>>>emptyMap()
                    );
                }
            });
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:WorkerSinkTaskTest.java

示例6: testRewindOnRebalanceDuringPoll

import org.easymock.IAnswer; //导入依赖的package包/类
@Test
public void testRewindOnRebalanceDuringPoll() throws Exception {
    expectInitializeTask();
    expectPollInitialAssignment();

    expectRebalanceDuringPoll().andAnswer(new IAnswer<Object>() {
        @Override
        public Object answer() throws Throwable {
            Map<TopicPartition, Long> offsets = sinkTaskContext.getValue().offsets();
            assertEquals(0, offsets.size());
            return null;
        }
    });

    expectStopTask();
    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    workerTask.iteration();
    workerTask.iteration();
    workerTask.stop();
    workerTask.close();

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:27,代码来源:WorkerSinkTaskThreadedTest.java

示例7: expectPollInitialAssignment

import org.easymock.IAnswer; //导入依赖的package包/类
private void expectPollInitialAssignment() throws Exception {
    final List<TopicPartition> partitions = Arrays.asList(TOPIC_PARTITION, TOPIC_PARTITION2, TOPIC_PARTITION3);

    sinkTask.open(partitions);
    EasyMock.expectLastCall();

    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(new IAnswer<ConsumerRecords<byte[], byte[]>>() {
        @Override
        public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
            rebalanceListener.getValue().onPartitionsAssigned(partitions);
            return ConsumerRecords.empty();
        }
    });
    EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);
    EasyMock.expect(consumer.position(TOPIC_PARTITION3)).andReturn(FIRST_OFFSET);

    sinkTask.put(Collections.<SinkRecord>emptyList());
    EasyMock.expectLastCall();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:WorkerSinkTaskThreadedTest.java

示例8: expectOnePoll

import org.easymock.IAnswer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private IExpectationSetters<Object> expectOnePoll() {
    // Currently the SinkTask's put() method will not be invoked unless we provide some data, so instead of
    // returning empty data, we return one record. The expectation is that the data will be ignored by the
    // response behavior specified using the return value of this method.
    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
            new IAnswer<ConsumerRecords<byte[], byte[]>>() {
                @Override
                public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
                    // "Sleep" so time will progress
                    time.sleep(1L);
                    ConsumerRecords<byte[], byte[]> records = new ConsumerRecords<>(
                            Collections.singletonMap(
                                    new TopicPartition(TOPIC, PARTITION),
                                    Arrays.asList(
                                            new ConsumerRecord<>(TOPIC, PARTITION, FIRST_OFFSET + recordsReturned, TIMESTAMP, TIMESTAMP_TYPE, 0L, 0, 0, RAW_KEY, RAW_VALUE)
                                    )));
                    recordsReturned++;
                    return records;
                }
            });
    EasyMock.expect(keyConverter.toConnectData(TOPIC, RAW_KEY)).andReturn(new SchemaAndValue(KEY_SCHEMA, KEY));
    EasyMock.expect(valueConverter.toConnectData(TOPIC, RAW_VALUE)).andReturn(new SchemaAndValue(VALUE_SCHEMA, VALUE));
    sinkTask.put(EasyMock.anyObject(Collection.class));
    return EasyMock.expectLastCall();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:27,代码来源:WorkerSinkTaskThreadedTest.java

示例9: expectStart

import org.easymock.IAnswer; //导入依赖的package包/类
private void expectStart(final List<ConsumerRecord<String, byte[]>> preexistingRecords,
                         final Map<byte[], Struct> deserializations) throws Exception {
    storeLog.start();
    PowerMock.expectLastCall().andAnswer(new IAnswer<Object>() {
        @Override
        public Object answer() throws Throwable {
            for (ConsumerRecord<String, byte[]> rec : preexistingRecords)
                capturedConsumedCallback.getValue().onCompletion(null, rec);
            return null;
        }
    });
    for (Map.Entry<byte[], Struct> deserializationEntry : deserializations.entrySet()) {
        // Note null schema because default settings for internal serialization are schema-less
        EasyMock.expect(converter.toConnectData(EasyMock.eq(TOPIC), EasyMock.aryEq(deserializationEntry.getKey())))
                .andReturn(new SchemaAndValue(null, structToMap(deserializationEntry.getValue())));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:KafkaConfigBackingStoreTest.java

示例10: expectConvertWriteRead

import org.easymock.IAnswer; //导入依赖的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()));
                }
            });
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:KafkaConfigBackingStoreTest.java

示例11: fileChannelMockExpectReadWithRandomBytes

import org.easymock.IAnswer; //导入依赖的package包/类
/**
 * Expectation setter for multiple reads where each one reads random bytes to the buffer.
 *
 * @param channelMock           The mocked FileChannel object
 * @param expectedBufferContent buffer that will be updated to contain the expected buffer content after each
 *                              `FileChannel.read` invocation
 * @param bufferSize            The buffer size
 * @throws IOException          If an I/O error occurs
 */
private void fileChannelMockExpectReadWithRandomBytes(final FileChannel channelMock,
                                                      final StringBuilder expectedBufferContent,
                                                      final int bufferSize) throws IOException {
    final int step = 20;
    final Random random = new Random();
    int remainingBytes = bufferSize;
    while (remainingBytes > 0) {
        final int mockedBytesRead = remainingBytes < step ? remainingBytes : random.nextInt(step);
        final StringBuilder sb = new StringBuilder();
        EasyMock.expect(channelMock.read(EasyMock.anyObject(ByteBuffer.class), EasyMock.anyInt())).andAnswer(new IAnswer<Integer>() {
            @Override
            public Integer answer() throws Throwable {
                ByteBuffer buffer = (ByteBuffer) EasyMock.getCurrentArguments()[0];
                for (int i = 0; i < mockedBytesRead; i++)
                    sb.append("a");
                buffer.put(sb.toString().getBytes());
                expectedBufferContent.append(sb);
                return mockedBytesRead;
            }
        });
        remainingBytes -= mockedBytesRead;
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:33,代码来源:UtilsTest.java

示例12: answerScheduleAtFixedRate

import org.easymock.IAnswer; //导入依赖的package包/类
private static IAnswer<ScheduledFuture<?>> answerScheduleAtFixedRate(
    FakeScheduledExecutor executor,
    int workCount) {

  return () -> {
    Object[] args = EasyMock.getCurrentArguments();
    Runnable work = (Runnable) args[0];
    long initialDelay = (Long) args[1];
    long period = (Long) args[2];
    TimeUnit unit = (TimeUnit) args[3];
    for (int i = 0; i <= workCount; i++) {
      addDelayedWork(executor, toMillis(initialDelay, unit) + i * toMillis(period, unit), work);
    }
    return null;
  };
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:FakeScheduledExecutor.java

示例13: mockServiceReference

import org.easymock.IAnswer; //导入依赖的package包/类
private ServiceReference mockServiceReference(final Map<String, Object> sProps) throws ClassNotFoundException {
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);

    Bundle b = EasyMock.createNiceMock(Bundle.class);
    EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.expect((Class)b.loadClass(Runnable.class.getName())).andReturn(Runnable.class);
    EasyMock.replay(b);

    EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
    EasyMock.replay(bc);

    ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
    EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
    EasyMock.expect(sref.getPropertyKeys()).andReturn(sProps.keySet().toArray(new String[] {})).anyTimes();
    EasyMock.expect(sref.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
        @Override
        public Object answer() throws Throwable {
            return sProps.get(EasyMock.getCurrentArguments()[0]);
        }
    }).anyTimes();
    EasyMock.replay(sref);
    return sref;
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:24,代码来源:RemoteServiceAdminCoreTest.java

示例14: testReadEvilPackage

import org.easymock.IAnswer; //导入依赖的package包/类
@Test(expected=ProtocolException.class)
public void testReadEvilPackage() throws Exception {

    expect(readableByteChannel.read(EasyMock.anyObject())).andAnswer(new IAnswer<Integer>() {

        @Override
        public Integer answer() throws Throwable {
            ByteBuffer buffer = (ByteBuffer)EasyMock.getCurrentArguments()[0];
            // an attacker could do that to provoke out of memory
            buffer.putInt(Integer.MAX_VALUE-1);
            return 1;
        }
    });
    replay(readableByteChannel);
    codec.read();
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:17,代码来源:LengthPrefixedCodecTest.java

示例15: testMatches

import org.easymock.IAnswer; //导入依赖的package包/类
/**
 * The test.
 */
@Test
public void testMatches() {
    NoteData note = new NoteData();
    note.setId(0L);
    FavoriteManagement favoriteManagement = EasyMock.createMock(FavoriteManagement.class);
    EasyMock.expect(favoriteManagement.isFavorite(EasyMock.anyLong())).andAnswer(
            new IAnswer<Boolean>() {
                @Override
                public Boolean answer() throws Throwable {
                    return EasyMock.getCurrentArguments()[0].equals(1L);
                }
            }).anyTimes();
    EasyMock.replay(favoriteManagement);

    Matcher<NoteData> matcher = new FavoriteMatcher(favoriteManagement);
    Assert.assertFalse(matcher.matches(note));

    note.setId(1L);
    Assert.assertTrue(matcher.matches(note));
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:24,代码来源:FavoriteMatcherTest.java


注:本文中的org.easymock.IAnswer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。