@Test
 public void removeConnection() throws Exception {
   ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
   ConnectionFactory<TestApi2> connectionFactory =
       new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
   connectionFactoryLocator.addConnectionFactory(connectionFactory);
   StubConnectionRepository connectionRepository = new StubConnectionRepository();
   connectionRepository.addConnection(
       connectionFactory.createConnection(
           new ConnectionData(
               "oauth2Provider", "provider1User1", null, null, null, null, null, null, null)));
   connectionRepository.addConnection(
       connectionFactory.createConnection(
           new ConnectionData(
               "oauth2Provider", "provider1User2", null, null, null, null, null, null, null)));
   assertEquals(2, connectionRepository.findConnections("oauth2Provider").size());
   ConnectController connectController =
       new ConnectController(connectionFactoryLocator, connectionRepository);
   List<DisconnectInterceptor<?>> interceptors = getDisconnectInterceptor();
   connectController.setDisconnectInterceptors(interceptors);
   MockMvc mockMvc = standaloneSetup(connectController).build();
   mockMvc
       .perform(delete("/connect/oauth2Provider/provider1User1"))
       .andExpect(redirectedUrl("/connect/oauth2Provider"));
   assertEquals(1, connectionRepository.findConnections("oauth2Provider").size());
   assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).preDisconnectInvoked);
   assertFalse(((TestConnectInterceptor<?>) (interceptors.get(0))).postDisconnectInvoked);
   assertNull(((TestConnectInterceptor<?>) (interceptors.get(0))).connectionFactory);
   assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).preDisconnectInvoked);
   assertTrue(((TestConnectInterceptor<?>) (interceptors.get(1))).postDisconnectInvoked);
   assertSame(
       connectionFactory, ((TestConnectInterceptor<?>) (interceptors.get(1))).connectionFactory);
 }
Beispiel #2
0
 @Test
 public void testDoLast() {
   Action<Task> action1 = createTaskAction();
   Action<Task> action2 = createTaskAction();
   int actionSizeBefore = getTask().getActions().size();
   assertSame(getTask(), getTask().doLast(action1));
   assertEquals(actionSizeBefore + 1, getTask().getActions().size());
   assertEquals(action1, getTask().getActions().get(getTask().getActions().size() - 1));
   assertSame(getTask(), getTask().doLast(action2));
   assertEquals(action2, getTask().getActions().get(getTask().getActions().size() - 1));
 }
  @Test
  @SuppressWarnings("unchecked")
  public void testDoWithRetry_ReadTimeOut() throws Exception {
    AmazonElasticMapReduceCustomClient client =
        new AmazonElasticMapReduceCustomClient("dummy", "dummy");
    client.setRequestInterval(100);

    Callable callable = mock(Callable.class);
    AmazonClientException exception =
        new AmazonClientException("Unable to execute HTTP request: Read timed out");
    when(callable.call()).thenThrow(exception, exception, exception).thenReturn(new Object());

    long startTime = System.currentTimeMillis();
    Object result = client.doThrottleSafe(callable);
    assertNotNull(result);
    assertThat(
        (System.currentTimeMillis() - startTime),
        greaterThanOrEqualTo(3 * client.getRequestInterval()));

    // now exceed retries
    client.setMaxRetriesOnConnectionErrors(2);
    when(callable.call()).thenThrow(exception, exception, exception).thenReturn(new Object());
    try {
      client.doThrottleSafe(callable);
      fail("should throw exception");
    } catch (Exception e) {
      assertSame(exception, e);
    }
  }
Beispiel #4
0
 @org.junit.Test
 public void testExcludes() {
   assertSame(test, test.exclude(TEST_PATTERN_1, TEST_PATTERN_2));
   assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2), test.getExcludes());
   test.exclude(TEST_PATTERN_3);
   assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2, TEST_PATTERN_3), test.getExcludes());
 }
 @Test
 public void getService_MUST_return_the_same_instance_WHEN_in_dev_mode() throws Exception {
   doReturn(Mode.DEV).when(configurationSource()).runMode();
   try (TemporaryPlayApplication ignored = new TemporaryPlayApplication()) {
     assertSame(serviceLoader.getService(), serviceLoader.getService());
   }
 }
Beispiel #6
0
 @Test
 public void testDeleteAllActions() {
   Action<Task> action1 = createTaskAction();
   Action<Task> action2 = createTaskAction();
   getTask().doLast(action1);
   getTask().doLast(action2);
   assertSame(getTask(), getTask().deleteAllActions());
   assertEquals(new ArrayList(), getTask().getActions());
 }
Beispiel #7
0
 @Test
 public void testTask() {
   assertTrue(getTask().isEnabled());
   assertEquals(TEST_TASK_NAME, getTask().getName());
   assertNull(getTask().getDescription());
   assertSame(project, getTask().getProject());
   assertEquals(getExpectedStandardOutputCapture(), getTask().getStandardOutputCapture());
   assertEquals(new HashMap(), getTask().getAdditionalProperties());
   assertNotNull(getTask().getInputs());
   assertNotNull(getTask().getOutputs());
   assertNotNull(getTask().getOnlyIf());
   assertTrue(getTask().getOnlyIf().isSatisfiedBy(getTask()));
 }
  // See https://github.com/netty/netty/issues/3967
  @Test
  public void testCloseChannelOnCreation() {
    EmbeddedChannel channel = new EmbeddedChannel();
    channel.close().syncUninterruptibly();

    final PendingWriteQueue queue = new PendingWriteQueue(channel.pipeline().firstContext());

    IllegalStateException ex = new IllegalStateException();
    ChannelPromise promise = channel.newPromise();
    queue.add(1L, promise);
    queue.removeAndFailAll(ex);
    assertSame(ex, promise.cause());
  }
 @Test
 public void getService_MUST_return_the_fallback_service_WHEN_default_service_is_removed()
     throws Exception {
   configureService(null);
   withDefaultService(
       DEFAULT_SERVICE_A_INSTANCE,
       () -> {
         withDefaultService(
             TestPlessServiceA.class,
             null,
             () -> {
               assertSame(serviceLoader.getService(), FALLBACK_SERVICE_INSTANCE);
             });
       });
 }
  @Test
  @SuppressWarnings("unchecked")
  public void testDoWithRetry_NoRetry() throws Exception {
    AmazonElasticMapReduceCustomClient client =
        new AmazonElasticMapReduceCustomClient("dummy", "dummy");
    client.setRequestInterval(100);

    Callable callable = mock(Callable.class);
    AmazonClientException exception = new AuthorizationErrorException("auth error");
    when(callable.call()).thenThrow(exception).thenReturn(new Object());

    try {
      client.doThrottleSafe(callable);
      fail("should throw exception");
    } catch (Exception e) {
      assertSame(exception, e);
    }
  }
 @Test
 public void getService_MUST_return_the_same_instance_WHEN_in_production_mode() throws Exception {
   doReturn(Mode.PROD).when(configurationSource()).runMode();
   assertSame(serviceLoader.getService(), serviceLoader.getService());
 }