Java Code Examples for org.easymock.EasyMock#reset()

The following examples show how to use org.easymock.EasyMock#reset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests adding while updating the networkConfig.
 */
@Test
public void testUpdateNetworkConfig() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24"))
    );
    interfaceIpAddresses.add(
            new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120"))
    );

    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses,
            MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    networkConfigListener
            .event(new NetworkConfigEvent(Type.CONFIG_UPDATED, dev3, RoutingService.ROUTER_CONFIG_CLASS));
    networkConfigService.addListener(networkConfigListener);
    verify(flowObjectiveService);
}
 
Example 2
Source File: PreAuthServiceTest.java    From knox with Apache License 2.0 6 votes vote down vote up
@Test
public void testIPValidator() throws ServletException {
  final HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
  EasyMock.expect(request.getRemoteAddr()).andReturn("10.1.23.42");
  EasyMock.replay(request);

  final FilterConfig filterConfig = EasyMock.createMock(FilterConfig.class);
  EasyMock.expect(filterConfig.getInitParameter(IPValidator.IP_ADDRESSES_PARAM))
      .andReturn("5.4.3.2,10.1.23.42").anyTimes();
  EasyMock.expect(filterConfig.getInitParameter(PreAuthService.VALIDATION_METHOD_PARAM))
      .andReturn(IPValidator.IP_VALIDATION_METHOD_VALUE).anyTimes();
  EasyMock.replay(filterConfig);

  List<PreAuthValidator> validators = PreAuthService.getValidators(filterConfig);
  assertEquals(validators.size(), 1);
  assertEquals(validators.get(0).getName(), IPValidator.IP_VALIDATION_METHOD_VALUE);
  assertTrue(PreAuthService.validate(request, filterConfig, validators));

  //Negative testing
  EasyMock.reset(request);
  EasyMock.expect(request.getRemoteAddr()).andReturn("10.10.22.33");
  EasyMock.replay(request);
  assertFalse(PreAuthService.validate(request, filterConfig, validators));
}
 
Example 3
Source File: BusApplicationListenerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testParentApplicationEvent() {
    AbstractRefreshableApplicationContext parent = new ClassPathXmlApplicationContext();
    parent.refresh();
    SpringBusFactory factory = new SpringBusFactory(parent);
    Bus bus = factory.createBus();
    CXFBusLifeCycleManager manager = bus.getExtension(CXFBusLifeCycleManager.class);
    BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
    manager.registerLifeCycleListener(listener);
    EasyMock.reset(listener);
    listener.preShutdown();
    EasyMock.expectLastCall().times(1);
    listener.postShutdown();
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(listener);
    parent.close();
    EasyMock.verify(listener);
}
 
Example 4
Source File: FailoverClusterInvokerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithRuntimeException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertEquals(0,expected.getCode());
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example 5
Source File: FailbackClusterInvokerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void resetInvokerToException() {
    EasyMock.reset(invoker);
    EasyMock.expect(invoker.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(FailbackClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker);
}
 
Example 6
Source File: IntentSynchronizerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the behavior of the submit API, both when the synchronizer has
 * leadership and when it does not.
 */
@Test
public void testSubmit() {
    IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
    Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1);

    // Set up expectations
    intentService.submit(intent);
    EasyMock.expect(intentService.getIntents()).andReturn(Collections.emptyList())
            .anyTimes();
    EasyMock.replay(intentService);

    // Give the intent synchronizer leadership so it will submit intents
    // to the intent service
    intentSynchronizer.modifyPrimary(true);

    // Test the submit
    intentSynchronizer.submit(intent);

    EasyMock.verify(intentService);

    // Now we'll remove leadership from the intent synchronizer and verify
    // that it does not submit any intents to the intent service when we
    // call the submit API
    EasyMock.reset(intentService);
    EasyMock.replay(intentService);

    intentSynchronizer.modifyPrimary(false);

    intentSynchronizer.submit(intent);

    EasyMock.verify(intentService);
}
 
Example 7
Source File: StickyTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public int testSticky(String methodName, boolean check) {
    if (methodName == null){
        url = url.addParameter(Constants.CLUSTER_STICKY_KEY, String.valueOf(check));
    }else {
        url = url.addParameter(methodName+"."+Constants.CLUSTER_STICKY_KEY, String.valueOf(check));
    }
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(StickyTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(StickyTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    invocation.setMethodName(methodName);
    
    int count = 0;
    for (int i = 0; i < runs; i++) {
        Assert.assertEquals(null, clusterinvoker.invoke(invocation));
        if(invoker1 == clusterinvoker.getSelectedInvoker()){
            count ++;
        }
    }
    return count;
}
 
Example 8
Source File: InvokerTelnetHandlerTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvaildMessage() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = invoke.telnet(mockChannel, "(");
    assertEquals("Invalid parameters, format: service.method(args)", result);
    EasyMock.reset(mockChannel);
}
 
Example 9
Source File: InvokerTelnetHandlerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvaildMessage() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = invoke.telnet(mockChannel, "(");
    assertEquals("Invalid parameters, format: service.method(args)", result);
    EasyMock.reset(mockChannel);
}
 
Example 10
Source File: OscillationUpdateCheckerTest.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testRunWithKeepingOscillation() {
  int n = 1;
  long currentTime = System.currentTimeMillis();
  alarm.getFifoSourceTimestamps().clear();
  while(alarm.getFifoSourceTimestamps().size() < oscillationProperties.getOscNumbers()) {
    alarm.getFifoSourceTimestamps().addFirst(currentTime - (10000 * n++));
  }
  setOscillating(alarm);
  assertTrue(alarm.isOscillating());
  assertTrue(alarm.isInternalActive());
  assertTrue(alarm.isActive());
  assertEquals("[OSC]", alarm.getInfo());
  assertNotEquals(tag.getTimestamp(), alarm.getSourceTimestamp());

  // record mocks
  EasyMock.reset(clusterCache, alarmCache, tagFacadeGateway);
  clusterCache.acquireWriteLockOnKey(OscillationUpdateChecker.LAST_CHECK_LONG);
  EasyMock.expect(clusterCache.getCopy(OscillationUpdateChecker.LAST_CHECK_LONG))
      .andReturn(Long.valueOf(OscillationUpdateChecker.SCAN_INTERVAL - 1000L));
  EasyMock.expect(alarmCache.findAlarm(oscillationUpdateChecker.alarmCacheQuery)).andReturn(Arrays.asList(alarm.getId()));
  EasyMock.expect(alarmCache.getCopy(alarm.getId())).andReturn(alarm);
  EasyMock.replay(clusterCache, alarmCache, tagFacadeGateway);

  // start test
  oscillationUpdateChecker.run();

  // Verify result
  EasyMock.verify(clusterCache, alarmCache, tagFacadeGateway);
  assertTrue(alarm.isOscillating());
  assertTrue(alarm.isInternalActive()); // remains unchanged as the evaluation does not take place
  assertEquals(true, alarm.isActive());
  assertEquals("[OSC]", alarm.getInfo());
  assertNotEquals(tag.getTimestamp(), alarm.getSourceTimestamp());
}
 
Example 11
Source File: FailfastClusterInvokerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void resetInvoker1ToException(){
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailfastClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
}
 
Example 12
Source File: ListTelnetHandlerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvaildMessage() throws RemotingException {
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel);
    String result = list.telnet(mockChannel, "xx");
    assertEquals("No such service xx", result);
    EasyMock.reset(mockChannel);
}
 
Example 13
Source File: ListTelnetHandlerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testList() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "");
    assertEquals("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService", result);
    EasyMock.reset(mockChannel);
}
 
Example 14
Source File: ListTelnetHandlerTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testListService() throws RemotingException {
    mockInvoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(mockInvoker.getInterface()).andReturn(DemoService.class).anyTimes();
    EasyMock.expect(mockInvoker.getUrl()).andReturn(URL.valueOf("dubbo://127.0.0.1:20885/demo")).anyTimes();
    EasyMock.expect(mockInvoker.invoke((Invocation) EasyMock.anyObject())).andReturn(new RpcResult("ok")).anyTimes();
    mockChannel = EasyMock.createMock(Channel.class);
    EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn("com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService").anyTimes();
    EasyMock.replay(mockChannel, mockInvoker);
    DubboProtocol.getDubboProtocol().export(mockInvoker);
    String result = list.telnet(mockChannel, "DemoService");
    assertEquals(methodsName, result);
    EasyMock.reset(mockChannel, mockInvoker);
}
 
Example 15
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setUpRemoveServant() throws Exception {
    EasyMock.reset(engine);
    engine.removeServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")));
    EasyMock.expectLastCall();
    EasyMock.replay(engine);
}
 
Example 16
Source File: FetcherManagerTest.java    From uReplicator with Apache License 2.0 4 votes vote down vote up
@Test
public void testConsumerFetcherManagerGroupByLeaderId() {
  fetcherThreadMap.clear();
  fetcherThreadMap.put("ConsumerFetcherThread-0", mockFetcherThread1);
  fetcherThreadMap.put("ConsumerFetcherThread-1", mockFetcherThread2);
  List<BlockingQueue<FetchedDataChunk>> messageQueue = new ArrayList<>();
  FetcherManagerGroupByLeaderId fetcherByLeaderId = new FetcherManagerGroupByLeaderId(
      "CompactConsumerFetcherManagerTest",
      new CustomizedConsumerConfig(new Properties()), fetcherThreadMap, messageQueue,
      kafkaClusterObserver);

  TopicPartition tp1 = new TopicPartition(testTopic1, 0);
  TopicPartition tp2 = new TopicPartition(testTopic2, 1);
  BlockingQueue<FetchedDataChunk> queue = new LinkedBlockingQueue<>(3);
  messageQueue.add(queue);

  PartitionOffsetInfo partitionOffsetInfo1 = new PartitionOffsetInfo(tp1, 0L, 10L);
  PartitionOffsetInfo partitionOffsetInfo2 = new PartitionOffsetInfo(tp2, 0L, 10L);

  EasyMock.reset(kafkaClusterObserver, mockFetcherThread1, mockFetcherThread2);
  EasyMock.expect(kafkaClusterObserver.findLeaderForPartitions(ImmutableList.of(tp1, tp2)))
      .andReturn(ImmutableMap.of(tp1, 0, tp2, 1));
  mockFetcherThread1.addPartitions(ImmutableMap.of(tp1, partitionOffsetInfo1));
  EasyMock.expectLastCall().once();

  mockFetcherThread2.addPartitions(ImmutableMap.of(tp2, partitionOffsetInfo2));
  EasyMock.expectLastCall().once();

  mockFetcherThread1.removePartitions(ImmutableSet.of(tp1));
  EasyMock.expectLastCall().once();

  mockFetcherThread2.removePartitions(ImmutableSet.of(tp1));
  EasyMock.expectLastCall().once();

  EasyMock.expect(mockFetcherThread1.initiateShutdown()).andReturn(true);

  EasyMock.expect(mockFetcherThread2.initiateShutdown()).andReturn(true);

  mockFetcherThread1.awaitShutdown();
  EasyMock.expectLastCall().once();

  mockFetcherThread2.awaitShutdown();
  EasyMock.expectLastCall().once();

  EasyMock.replay(kafkaClusterObserver, mockFetcherThread1, mockFetcherThread2);

  fetcherByLeaderId.start();

  fetcherByLeaderId.addTopicPartition(tp1, partitionOffsetInfo1);
  fetcherByLeaderId.addTopicPartition(tp2, partitionOffsetInfo2);

  fetcherByLeaderId.doWork();
  Assert.assertEquals(fetcherByLeaderId.getTopicPartitions().size(), 2);

  fetcherByLeaderId.removeTopicPartition(tp1);
  fetcherByLeaderId.doWork();
  Assert.assertEquals(fetcherByLeaderId.getTopicPartitions().size(), 1);

  fetcherByLeaderId.shutdown();
  EasyMock.verify(kafkaClusterObserver, mockFetcherThread1, mockFetcherThread2);
}
 
Example 17
Source File: CurrentTelnetHandlerTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    EasyMock.reset(mockChannel);
}
 
Example 18
Source File: CompatibleFilterFilterTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    EasyMock.reset(invocation, invoker);
}
 
Example 19
Source File: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setUpRemoveServant() throws Exception {
    EasyMock.reset(engine);
    engine.removeServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")));
    EasyMock.expectLastCall();
    EasyMock.replay(engine);
}
 
Example 20
Source File: HelixHandlerTest.java    From uReplicator with Apache License 2.0 4 votes vote down vote up
@Test
public void testManagerWorkerHelixInconsistentMessages() throws Exception {

  WorkerConf workerConf = TestUtils.initWorkerConf();
  Properties helixProps = WorkerUtils.loadAndValidateHelixProps(workerConf.getHelixConfigFile());
  // setup helix controller
  String route = String.format("%s-%s-0", TestUtils.SRC_CLUSTER, TestUtils.DST_CLUSTER);
  String routeForHelix = String.format("@%s@%s", TestUtils.SRC_CLUSTER, TestUtils.DST_CLUSTER);
  String rout2 = String.format("%s-%s-0", TestUtils.SRC_CLUSTER_2, TestUtils.DST_CLUSTER);
  String route2ForHelix = String.format("@%s@%s", TestUtils.SRC_CLUSTER_2, TestUtils.DST_CLUSTER);

  ZKHelixAdmin helixAdmin = TestUtils.initHelixClustersForWorkerTest(helixProps, route, rout2);
  String deployment = helixProps.getProperty("federated.deployment.name");
  String managerHelixClusterName = WorkerUtils.getManagerWorkerHelixClusterName(deployment);
  String instanceId = helixProps.getProperty("instanceId");

  EasyMock.reset(mockWorker);
  mockWorker.start(TestUtils.SRC_CLUSTER, TestUtils.DST_CLUSTER, "0", deployment);
  EasyMock.expectLastCall().times(1);

  mockWorker.start(TestUtils.SRC_CLUSTER_2, TestUtils.DST_CLUSTER, "0", deployment);
  EasyMock.expectLastCall().times(1);

  mockWorker.cleanShutdown();
  EasyMock.expectLastCall().anyTimes();

  EasyMock.expect(mockWorker.isRunning()).andReturn(false).anyTimes();

  EasyMock.replay(mockWorker);


  ManagerWorkerHelixHandler managerWorkerHelixHandler = new ManagerWorkerHelixHandler(workerConf,
      helixProps,
      mockWorker);
  managerWorkerHelixHandler.start();

  TestUtils
      .updateRouteWithValidation(managerHelixClusterName, routeForHelix, instanceId, helixAdmin,
          "ONLINE", "ONLINE");
  TestUtils
      .updateRouteWithValidation(managerHelixClusterName, route2ForHelix, instanceId, helixAdmin,
          "ONLINE", "ERROR");
  // mark offline to error not propagate to worker
  TestUtils
      .updateRouteWithValidation(managerHelixClusterName, route2ForHelix, instanceId, helixAdmin,
          "OFFLINE", "ERROR");

  managerWorkerHelixHandler.shutdown();

  // set the first route to offline
  IdealState idealState = TestUtils
      .buildManagerWorkerCustomIdealState(routeForHelix, Collections.singletonList(instanceId),
          "OFFLINE");
  helixAdmin.setResourceIdealState(managerHelixClusterName, routeForHelix, idealState);

  managerWorkerHelixHandler = new ManagerWorkerHelixHandler(workerConf,
      helixProps,
      mockWorker);
  managerWorkerHelixHandler.start();

  Thread.sleep(1000);

  ExternalView externalView = helixAdmin
      .getResourceExternalView(managerHelixClusterName, route2ForHelix);
  Assert.assertNotNull(externalView);
  Assert.assertNotNull(externalView.getStateMap("0"));
  LOGGER.info("ExternalView: {}", externalView);
  Assert.assertEquals(externalView.getStateMap("0").get("0"), "OFFLINE");

  TestUtils
      .updateRouteWithValidation(managerHelixClusterName, route2ForHelix, instanceId, helixAdmin,
          "ONLINE", "ONLINE");
}