• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PrepareOnlyThisForTest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: assertThatPrepareOnlyThisForTestWorks

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
@Test
@PrepareOnlyThisForTest( { NioDatagramSession.class, NioProcessor.class, AbstractIoSession.class })
public void assertThatPrepareOnlyThisForTestWorks() throws Exception {
    final String scheduleRemoveMethodName = "scheduleRemove";

    Executor executor = createMock(Executor.class);
    NioProcessor objectUnderTest = createPartialMock(NioProcessor.class, new String[] { scheduleRemoveMethodName }, executor);
    NioDatagramSession session = createMock(NioDatagramSession.class);

    expect(session.isConnected()).andReturn(false);
    expectPrivate(objectUnderTest, scheduleRemoveMethodName, session).once();

    replay(objectUnderTest, executor, session);

    assertFalse(Whitebox.<Boolean> invokeMethod(objectUnderTest, "flushNow", session, 20L));

    verify(objectUnderTest, executor, session);
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:19,代码来源:PrepareOnlyThisForTestAnnotationTest.java


示例2: testInterceptorPartitionSetOnTooLargeRecord

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
@PrepareOnlyThisForTest(Metadata.class)
@Test
public void testInterceptorPartitionSetOnTooLargeRecord() throws Exception {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    props.setProperty(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, "1");
    String topic = "topic";
    ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value");
    
    KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(),
            new StringSerializer());
    Metadata metadata = PowerMock.createNiceMock(Metadata.class);
    MemberModifier.field(KafkaProducer.class, "metadata").set(producer, metadata);
    final Cluster cluster = new Cluster(
        "dummy",
        Collections.singletonList(new Node(0, "host1", 1000)),
        Arrays.asList(new PartitionInfo(topic, 0, null, null, null)),
        Collections.<String>emptySet(),
        Collections.<String>emptySet());
    EasyMock.expect(metadata.fetch()).andReturn(cluster).once();
    
    // Mock interceptors field
    ProducerInterceptors interceptors = PowerMock.createMock(ProducerInterceptors.class);
    EasyMock.expect(interceptors.onSend(record)).andReturn(record);
    interceptors.onSendError(EasyMock.eq(record), EasyMock.<TopicPartition>notNull(), EasyMock.<Exception>notNull());
    EasyMock.expectLastCall();
    MemberModifier.field(KafkaProducer.class, "interceptors").set(producer, interceptors);
    
    PowerMock.replay(metadata);
    EasyMock.replay(interceptors);
    producer.send(record);
    
    EasyMock.verify(interceptors);
    
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:36,代码来源:KafkaProducerTest.java


示例3: testMetadataFetch

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
@PrepareOnlyThisForTest(Metadata.class)
@Test
public void testMetadataFetch() throws Exception {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(), new StringSerializer());
    Metadata metadata = PowerMock.createNiceMock(Metadata.class);
    MemberModifier.field(KafkaProducer.class, "metadata").set(producer, metadata);

    String topic = "topic";
    ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value");
    Collection<Node> nodes = Collections.singletonList(new Node(0, "host1", 1000));
    final Cluster emptyCluster = new Cluster(null, nodes,
            Collections.<PartitionInfo>emptySet(),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());
    final Cluster cluster = new Cluster(
            "dummy",
            Collections.singletonList(new Node(0, "host1", 1000)),
            Arrays.asList(new PartitionInfo(topic, 0, null, null, null)),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());

    // Expect exactly one fetch for each attempt to refresh while topic metadata is not available
    final int refreshAttempts = 5;
    EasyMock.expect(metadata.fetch()).andReturn(emptyCluster).times(refreshAttempts - 1);
    EasyMock.expect(metadata.fetch()).andReturn(cluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.send(record);
    PowerMock.verify(metadata);

    // Expect exactly one fetch if topic metadata is available
    PowerMock.reset(metadata);
    EasyMock.expect(metadata.fetch()).andReturn(cluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.send(record, null);
    PowerMock.verify(metadata);

    // Expect exactly one fetch if topic metadata is available
    PowerMock.reset(metadata);
    EasyMock.expect(metadata.fetch()).andReturn(cluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.partitionsFor(topic);
    PowerMock.verify(metadata);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:49,代码来源:KafkaProducerTest.java


示例4: testMetadataFetchOnStaleMetadata

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
@PrepareOnlyThisForTest(Metadata.class)
@Test
public void testMetadataFetchOnStaleMetadata() throws Exception {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(), new StringSerializer());
    Metadata metadata = PowerMock.createNiceMock(Metadata.class);
    MemberModifier.field(KafkaProducer.class, "metadata").set(producer, metadata);

    String topic = "topic";
    ProducerRecord<String, String> initialRecord = new ProducerRecord<>(topic, "value");
    // Create a record with a partition higher than the initial (outdated) partition range
    ProducerRecord<String, String> extendedRecord = new ProducerRecord<>(topic, 2, null, "value");
    Collection<Node> nodes = Collections.singletonList(new Node(0, "host1", 1000));
    final Cluster emptyCluster = new Cluster(null, nodes,
            Collections.<PartitionInfo>emptySet(),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());
    final Cluster initialCluster = new Cluster(
            "dummy",
            Collections.singletonList(new Node(0, "host1", 1000)),
            Arrays.asList(new PartitionInfo(topic, 0, null, null, null)),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());
    final Cluster extendedCluster = new Cluster(
            "dummy",
            Collections.singletonList(new Node(0, "host1", 1000)),
            Arrays.asList(
                    new PartitionInfo(topic, 0, null, null, null),
                    new PartitionInfo(topic, 1, null, null, null),
                    new PartitionInfo(topic, 2, null, null, null)),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());

    // Expect exactly one fetch for each attempt to refresh while topic metadata is not available
    final int refreshAttempts = 5;
    EasyMock.expect(metadata.fetch()).andReturn(emptyCluster).times(refreshAttempts - 1);
    EasyMock.expect(metadata.fetch()).andReturn(initialCluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.send(initialRecord);
    PowerMock.verify(metadata);

    // Expect exactly one fetch if topic metadata is available and records are still within range
    PowerMock.reset(metadata);
    EasyMock.expect(metadata.fetch()).andReturn(initialCluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.send(initialRecord, null);
    PowerMock.verify(metadata);

    // Expect exactly two fetches if topic metadata is available but metadata response still returns
    // the same partition size (either because metadata are still stale at the broker too or because
    // there weren't any partitions added in the first place).
    PowerMock.reset(metadata);
    EasyMock.expect(metadata.fetch()).andReturn(initialCluster).once();
    EasyMock.expect(metadata.fetch()).andReturn(initialCluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    try {
        producer.send(extendedRecord, null);
        fail("Expected KafkaException to be raised");
    } catch (KafkaException e) {
        // expected
    }
    PowerMock.verify(metadata);

    // Expect exactly two fetches if topic metadata is available but outdated for the given record
    PowerMock.reset(metadata);
    EasyMock.expect(metadata.fetch()).andReturn(initialCluster).once();
    EasyMock.expect(metadata.fetch()).andReturn(extendedCluster).once();
    EasyMock.expect(metadata.fetch()).andThrow(new IllegalStateException("Unexpected call to metadata.fetch()")).anyTimes();
    PowerMock.replay(metadata);
    producer.send(extendedRecord, null);
    PowerMock.verify(metadata);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:77,代码来源:KafkaProducerTest.java


示例5: testHeaders

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
@PrepareOnlyThisForTest(Metadata.class)
@Test
public void testHeaders() throws Exception {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    ExtendedSerializer keySerializer = PowerMock.createNiceMock(ExtendedSerializer.class);
    ExtendedSerializer valueSerializer = PowerMock.createNiceMock(ExtendedSerializer.class);

    KafkaProducer<String, String> producer = new KafkaProducer<>(props, keySerializer, valueSerializer);
    Metadata metadata = PowerMock.createNiceMock(Metadata.class);
    MemberModifier.field(KafkaProducer.class, "metadata").set(producer, metadata);

    String topic = "topic";
    Collection<Node> nodes = Collections.singletonList(new Node(0, "host1", 1000));

    final Cluster cluster = new Cluster(
            "dummy",
            Collections.singletonList(new Node(0, "host1", 1000)),
            Arrays.asList(new PartitionInfo(topic, 0, null, null, null)),
            Collections.<String>emptySet(),
            Collections.<String>emptySet());


    EasyMock.expect(metadata.fetch()).andReturn(cluster).anyTimes();

    PowerMock.replay(metadata);

    String value = "value";

    ProducerRecord<String, String> record = new ProducerRecord<>(topic, value);
    EasyMock.expect(keySerializer.serialize(topic, record.headers(), null)).andReturn(null).once();
    EasyMock.expect(valueSerializer.serialize(topic, record.headers(), value)).andReturn(value.getBytes()).once();

    PowerMock.replay(keySerializer);
    PowerMock.replay(valueSerializer);


    //ensure headers can be mutated pre send.
    record.headers().add(new RecordHeader("test", "header2".getBytes()));
    
    producer.send(record, null);
    
    //ensure headers are closed and cannot be mutated post send
    try {
        record.headers().add(new RecordHeader("test", "test".getBytes()));
        fail("Expected IllegalStateException to be raised");
    } catch (IllegalStateException ise) {
        //expected
    }
    
    //ensure existing headers are not changed, and last header for key is still original value
    assertTrue(Arrays.equals(record.headers().lastHeader("test").value(), "header2".getBytes()));

    PowerMock.verify(valueSerializer);
    PowerMock.verify(keySerializer);

}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:58,代码来源:KafkaProducerTest.java


示例6: addFullyQualifiedNames

import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; //导入依赖的package包/类
private void addFullyQualifiedNames(Set<String> all, PrepareOnlyThisForTest annotation) {
    String[] fullyQualifiedNames = annotation.fullyQualifiedNames();
    addFullyQualifiedNames(all, fullyQualifiedNames);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:5,代码来源:PrepareForTestExtractorImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AttributeStats类代码示例发布时间:2022-05-23
下一篇:
Java XIncludeAwareParserConfiguration类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap