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


Java PowerMock類代碼示例

本文整理匯總了Java中org.powermock.api.easymock.PowerMock的典型用法代碼示例。如果您正苦於以下問題:Java PowerMock類的具體用法?Java PowerMock怎麽用?Java PowerMock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: setUp

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    worker = PowerMock.createMock(Worker.class);
    EasyMock.expect(worker.isSinkConnector(CONN1)).andStubReturn(Boolean.FALSE);
    time = new MockTime();

    herder = PowerMock.createPartialMock(DistributedHerder.class, new String[]{"backoff", "updateDeletedConnectorStatus"},
            new DistributedConfig(HERDER_CONFIG), worker, WORKER_ID, statusBackingStore, configBackingStore, member, MEMBER_URL, time);

    configUpdateListener = herder.new ConfigUpdateListener();
    rebalanceListener = herder.new RebalanceListener();
    plugins = PowerMock.createMock(Plugins.class);
    pluginLoader = PowerMock.createMock(PluginClassLoader.class);
    delegatingLoader = PowerMock.createMock(DelegatingClassLoader.class);
    PowerMock.mockStatic(Plugins.class);
    PowerMock.expectPrivate(herder, "updateDeletedConnectorStatus").andVoid().anyTimes();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,代碼來源:DistributedHerderTest.java

示例2: testCreateConnectorAlreadyExists

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testCreateConnectorAlreadyExists() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);

    member.wakeup();
    PowerMock.expectLastCall();
    // CONN1 already exists
    putConnectorCallback.onCompletion(EasyMock.<AlreadyExistsException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // No immediate action besides this -- change will be picked up via the config log

    PowerMock.replayAll();

    herder.putConnectorConfig(CONN1, CONN1_CONFIG, false, putConnectorCallback);
    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:DistributedHerderTest.java

示例3: testSourceTasks

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testSourceTasks() {
    PowerMock.replayAll();

    connector.start(sourceProperties);
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    assertEquals(1, taskConfigs.size());
    assertEquals(FILENAME,
            taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));
    assertEquals(SINGLE_TOPIC,
            taskConfigs.get(0).get(FileStreamSourceConnector.TOPIC_CONFIG));

    // Should be able to return fewer than requested #
    taskConfigs = connector.taskConfigs(2);
    assertEquals(1, taskConfigs.size());
    assertEquals(FILENAME,
            taskConfigs.get(0).get(FileStreamSourceConnector.FILE_CONFIG));
    assertEquals(SINGLE_TOPIC,
            taskConfigs.get(0).get(FileStreamSourceConnector.TOPIC_CONFIG));

    PowerMock.verifyAll();
}
 
開發者ID:wngn123,項目名稱:wngn-jms-kafka,代碼行數:23,代碼來源:FileStreamSourceConnectorTest.java

示例4: testStartStop

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testStartStop() throws Exception {
    expectConfigure();
    expectStart(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
    expectStop();

    PowerMock.replayAll();

    configStorage.setupAndCreateKafkaBasedLog(TOPIC, DEFAULT_DISTRIBUTED_CONFIG);

    assertEquals(TOPIC, capturedTopic.getValue());
    assertEquals("org.apache.kafka.common.serialization.StringSerializer", capturedProducerProps.getValue().get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG));
    assertEquals("org.apache.kafka.common.serialization.ByteArraySerializer", capturedProducerProps.getValue().get(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG));
    assertEquals("org.apache.kafka.common.serialization.StringDeserializer", capturedConsumerProps.getValue().get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG));
    assertEquals("org.apache.kafka.common.serialization.ByteArrayDeserializer", capturedConsumerProps.getValue().get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG));

    assertEquals(TOPIC, capturedNewTopic.getValue().name());
    assertEquals(1, capturedNewTopic.getValue().numPartitions());
    assertEquals(TOPIC_REPLICATION_FACTOR, capturedNewTopic.getValue().replicationFactor());
    configStorage.start();
    configStorage.stop();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:KafkaConfigBackingStoreTest.java

示例5: testSinkTasks

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testSinkTasks() {
    PowerMock.replayAll();

    connector.start(sinkProperties);
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    assertEquals(1, taskConfigs.size());
    assertEquals(FILENAME, taskConfigs.get(0).get(FileStreamSinkConnector.FILE_CONFIG));

    taskConfigs = connector.taskConfigs(2);
    assertEquals(2, taskConfigs.size());
    for (int i = 0; i < 2; i++) {
        assertEquals(FILENAME, taskConfigs.get(0).get(FileStreamSinkConnector.FILE_CONFIG));
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:18,代碼來源:FileStreamSinkConnectorTest.java

示例6: testJoinAssignment

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testJoinAssignment() throws Exception {
    // Join group and get assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    EasyMock.expect(worker.getPlugins()).andReturn(plugins);
    expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));
    expectPostRebalanceCatchup(SNAPSHOT);
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);

    EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);
    worker.startTask(EasyMock.eq(TASK1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Map<String, String>>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:26,代碼來源:DistributedHerderTest.java

示例7: whenFindByIdCalledWithUnknownIdThenReturnEmptyBotConfig

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void whenFindByIdCalledWithUnknownIdThenReturnEmptyBotConfig() throws Exception {

    expect(ConfigurationManager.loadConfig(
            eq(BotsType.class),
            eq(BOTS_CONFIG_XML_FILENAME),
            eq(BOTS_CONFIG_XSD_FILENAME))).
            andReturn(allTheInternalBotsConfig());

    PowerMock.replayAll();

    final BotConfigRepository botConfigRepository = new BotConfigRepositoryXmlDatastore();
    final BotConfig botConfig = botConfigRepository.findById(UNKNOWN_BOT_ID);

    assertThat(botConfig.getId()).isEqualTo(null);
    assertThat(botConfig.getAlias()).isEqualTo(null);
    assertThat(botConfig.getBaseUrl()).isEqualTo(null);
    assertThat(botConfig.getUsername()).isEqualTo(null);
    assertThat(botConfig.getPassword()).isEqualTo(null);

    PowerMock.verifyAll();
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:23,代碼來源:TestBotConfigRepository.java

示例8: whenSaveCalledWithUnknownIdThenExpectEmptyBotConfigToBeReturned

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void whenSaveCalledWithUnknownIdThenExpectEmptyBotConfigToBeReturned() throws Exception {

    expect(ConfigurationManager.loadConfig(
            eq(BotsType.class),
            eq(BOTS_CONFIG_XML_FILENAME),
            eq(BOTS_CONFIG_XSD_FILENAME))).
            andReturn(allTheInternalBotsConfig());

    PowerMock.replayAll();

    final BotConfigRepository botConfigRepository = new BotConfigRepositoryXmlDatastore();
    final BotConfig botConfig = botConfigRepository.save(someUpdatedExternalBotConfigWithUnknownId());

    assertThat(botConfig.getId()).isEqualTo(null);
    assertThat(botConfig.getAlias()).isEqualTo(null);
    assertThat(botConfig.getBaseUrl()).isEqualTo(null);
    assertThat(botConfig.getUsername()).isEqualTo(null);
    assertThat(botConfig.getPassword()).isEqualTo(null);

    PowerMock.verifyAll();
}
 
開發者ID:gazbert,項目名稱:bxbot-ui-server,代碼行數:23,代碼來源:TestBotConfigRepository.java

示例9: testMetadata

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testMetadata() {
    EasyMock.expect(configStorage.snapshot()).andReturn(configState1);

    PowerMock.replayAll();

    List<ProtocolMetadata> serialized = coordinator.metadata();
    assertEquals(1, serialized.size());

    ProtocolMetadata defaultMetadata = serialized.get(0);
    assertEquals(WorkerCoordinator.DEFAULT_SUBPROTOCOL, defaultMetadata.name());
    ConnectProtocol.WorkerState state = ConnectProtocol.deserializeMetadata(defaultMetadata.metadata());
    assertEquals(1, state.offset());

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:17,代碼來源:WorkerCoordinatorTest.java

示例10: testSinkTasks

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
  public void testSinkTasks() {
    PowerMock.replayAll();
    connector.start(sinkProperties);
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    Assert.assertEquals(1, taskConfigs.size());
    Assert.assertEquals("localhost", taskConfigs.get(0).get("locator.host"));
    Assert.assertEquals("12345", taskConfigs.get(0).get("locator.port"));
    Assert.assertEquals("100", taskConfigs.get(0).get("batch.size"));;
    Assert.assertEquals("topic1, topic2, topic3", taskConfigs.get(0).get("topics"));
    Assert.assertEquals("table1, table2, table3", taskConfigs.get(0).get("ampool.tables"));

//    System.out.println(taskConfigs.get(0).get("locator.host"));
//    System.out.println(taskConfigs.get(0).get("locator.port"));
//    System.out.println(taskConfigs.get(0).get("batch.size"));
//    System.out.println(taskConfigs.get(0).get("topics"));
//    System.out.println(taskConfigs.get(0).get("ampool.tables"));
    PowerMock.verifyAll();
  }
 
開發者ID:ampool,項目名稱:monarch,代碼行數:20,代碼來源:AmpoolSinkConnectorTest.java

示例11: testTaskConfig

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testTaskConfig() {
    PowerMock.replayAll();
    connector.start(buildSinkProperties());
    List<Map<String, String>> taskConfigs = connector.taskConfigs(1);
    Assert.assertEquals("localhost:24225", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CONNECT));
    Assert.assertEquals("100", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_MAX_BUFFER_BYTES));
    Assert.assertEquals("10", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_BUFFER_CHUNK_INITIAL_BYTES));
    Assert.assertEquals("10", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_BUFFER_CHUNK_RETENTION_BYTES));
    Assert.assertEquals("500", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_FLUSH_INTERVAL));
    Assert.assertEquals("true", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_ACK_RESPONSE_MODE));
    Assert.assertEquals("/tmp/fluency", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_FILE_BACKUP_DIR));
    Assert.assertEquals("120", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_WAIT_UNTIL_BUFFER_FLUSHED));
    Assert.assertEquals("120", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_WAIT_UNTIL_FLUSHER_TERMINATED));
    Assert.assertEquals("true", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_JVM_HEAP_BUFFER_MODE));
    Assert.assertEquals("true", taskConfigs.get(0).get(FluentdSinkConnectorConfig.FLUENTD_CLIENT_TIMESTAMP_INTEGER));
    PowerMock.verifyAll();
}
 
開發者ID:fluent,項目名稱:kafka-connect-fluentd,代碼行數:19,代碼來源:FluentdSinkConnectorTest.java

示例12: testSendRecordsCorruptTimestamp

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

示例13: testSendRecordsNoTimestamp

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

示例14: expectOffsetFlush

import org.powermock.api.easymock.PowerMock; //導入依賴的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

示例15: testFlushFailureReplacesOffsets

import org.powermock.api.easymock.PowerMock; //導入依賴的package包/類
@Test
public void testFlushFailureReplacesOffsets() throws Exception {
    // When a flush fails, we shouldn't just lose the offsets. Instead, they should be restored
    // such that a subsequent flush will write them.

    @SuppressWarnings("unchecked")
    final Callback<Void> callback = PowerMock.createMock(Callback.class);
    // First time the write fails
    expectStore(OFFSET_KEY, OFFSET_KEY_SERIALIZED, OFFSET_VALUE, OFFSET_VALUE_SERIALIZED, callback, true, null);
    // Second time it succeeds
    expectStore(OFFSET_KEY, OFFSET_KEY_SERIALIZED, OFFSET_VALUE, OFFSET_VALUE_SERIALIZED, callback, false, null);
    // Third time it has no data to flush so we won't get past beginFlush()

    PowerMock.replayAll();

    writer.offset(OFFSET_KEY, OFFSET_VALUE);
    assertTrue(writer.beginFlush());
    writer.doFlush(callback).get(1000, TimeUnit.MILLISECONDS);
    assertTrue(writer.beginFlush());
    writer.doFlush(callback).get(1000, TimeUnit.MILLISECONDS);
    assertFalse(writer.beginFlush());

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:OffsetStorageWriterTest.java


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