Search in sources :

Example 1 with LoadBalancerException

use of com.netflix.titus.api.loadbalancer.service.LoadBalancerException in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnectorTest method validateExceptionsAreUnmodifiedWithMockClientTest.

@Test
public void validateExceptionsAreUnmodifiedWithMockClientTest() {
    Class defaultExceptionClass = TargetGroupAssociationLimitException.class;
    TestSubscriber testSubscriber = new TestSubscriber();
    AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class);
    when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(defaultExceptionClass);
    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
    awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    List<Throwable> errors = testSubscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    Throwable throwable = errors.get(0);
    assertFalse(throwable instanceof LoadBalancerException);
    assertTrue(throwable instanceof TargetGroupAssociationLimitException);
}
Also used : LoadBalancerException(com.netflix.titus.api.loadbalancer.service.LoadBalancerException) TestSubscriber(rx.observers.TestSubscriber) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) TargetGroupAssociationLimitException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupAssociationLimitException) Test(org.junit.Test)

Example 2 with LoadBalancerException

use of com.netflix.titus.api.loadbalancer.service.LoadBalancerException in project titus-control-plane by Netflix.

the class DefaultLoadBalancerJobValidatorTest method testValidateMaxLoadBalancers.

@Test
public void testValidateMaxLoadBalancers() throws Exception {
    when(jobOperations.getJob(JOB_ID)).thenReturn(Optional.of(Job.<ServiceJobExt>newBuilder().withId(JOB_ID).withStatus(JobStatus.newBuilder().withState(JobState.Accepted).build()).withJobDescriptor(JobDescriptor.<ServiceJobExt>newBuilder().withExtensions(ServiceJobExt.newBuilder().build()).withContainer(Container.newBuilder().withImage(Image.newBuilder().build()).withContainerResources(ContainerResources.newBuilder().withAllocateIP(true).build()).build()).build()).build()));
    when(loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob()).thenReturn(30);
    for (int i = 0; i < loadBalancerValidationConfiguration.getMaxLoadBalancersPerJob() + 1; i++) {
        loadBalancerStore.addOrUpdateLoadBalancer(new JobLoadBalancer(JOB_ID, "LoadBalancer-" + i), JobLoadBalancer.State.ASSOCIATED).await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    }
    Throwable thrown = catchThrowable(() -> loadBalancerValidator.validateJobId(JOB_ID));
    assertThat(thrown).isInstanceOf(LoadBalancerException.class);
    assertThat(((LoadBalancerException) thrown).getErrorCode()).isEqualTo(LoadBalancerException.ErrorCode.JobMaxLoadBalancers);
}
Also used : ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) LoadBalancerException(com.netflix.titus.api.loadbalancer.service.LoadBalancerException) AssertionsForClassTypes.catchThrowable(org.assertj.core.api.AssertionsForClassTypes.catchThrowable) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Aggregations

LoadBalancerException (com.netflix.titus.api.loadbalancer.service.LoadBalancerException)2 Test (org.junit.Test)2 AmazonElasticLoadBalancingAsync (com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync)1 TargetGroupAssociationLimitException (com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupAssociationLimitException)1 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)1 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)1 AssertionsForClassTypes.catchThrowable (org.assertj.core.api.AssertionsForClassTypes.catchThrowable)1 TestSubscriber (rx.observers.TestSubscriber)1