use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateListeners.
@ParallelTest
public void testValidateListeners() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
GenericKafkaListener listener2 = new GenericKafkaListenerBuilder().withName("listener2").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
List<GenericKafkaListener> listeners = asList(listener1, listener2);
ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners);
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testInvalidNames.
@ParallelTest
public void testInvalidNames() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener 1").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
GenericKafkaListener listener2 = new GenericKafkaListenerBuilder().withName("LISTENER2").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
GenericKafkaListener listener3 = new GenericKafkaListenerBuilder().withName("listener12345678901234567890").withPort(9902).withType(KafkaListenerType.INTERNAL).build();
List<GenericKafkaListener> listeners = asList(listener1, listener2, listener3);
assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder("listener names [listener 1, LISTENER2, listener12345678901234567890] are invalid and do not match the pattern ^[a-z0-9]{1,11}$"));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testRouteListener.
@ParallelTest
public void testRouteListener() {
String name = "route";
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.ROUTE).withTls(true).withNewConfiguration().withIngressClass("my-ingress").withUseServiceDnsDomain(true).withExternalTrafficPolicy(ExternalTrafficPolicy.LOCAL).withIpFamilyPolicy(IpFamilyPolicy.REQUIRE_DUAL_STACK).withIpFamilies(IpFamily.IPV4, IpFamily.IPV6).withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).withLoadBalancerSourceRanges(asList("10.0.0.0/8", "130.211.204.1/32")).withFinalizers(asList("service.kubernetes.io/load-balancer-cleanup")).withNewBootstrap().withAlternativeNames(asList("my-name-1", "my-name-2")).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build()).endConfiguration().build();
List<GenericKafkaListener> listeners = asList(listener1);
List<String> expectedErrors = asList("listener " + name + " cannot configure ingressClass because it is not Ingress based listener", "listener " + name + " cannot configure useServiceDnsDomain because it is not internal listener", "listener " + name + " cannot configure externalTrafficPolicy because it is not LoadBalancer or NodePort based listener", "listener " + name + " cannot configure loadBalancerSourceRanges because it is not LoadBalancer based listener", "listener " + name + " cannot configure finalizers because it is not LoadBalancer based listener", "listener " + name + " cannot configure preferredAddressType because it is not NodePort based listener", "listener " + name + " cannot configure bootstrap.loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure bootstrap.nodePort because it is not NodePort based listener", "listener " + name + " cannot configure brokers[].loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure brokers[].nodePort because it is not NodePort based listener");
assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateTimeoutsOauth.
@ParallelTest
public void testValidateTimeoutsOauth() {
KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withConnectTimeoutSeconds(0);
GenericKafkaListenerBuilder listenerBuilder = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(authBuilder.build());
List<GenericKafkaListener> listeners = asList(listenerBuilder.withAuth(authBuilder.build()).build());
Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'connectTimeoutSeconds' needs to be a positive integer (set to: 0)")));
// set valid connectTimeoutSeconds
authBuilder.withConnectTimeoutSeconds(1);
List<GenericKafkaListener> listeners2 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners2));
assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'connectTimeoutSeconds' needs to be a positive integer"))));
//
// Repeat for readTimeoutSeconds
//
authBuilder.withConnectTimeoutSeconds(null).withReadTimeoutSeconds(0);
List<GenericKafkaListener> listeners3 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners3));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'readTimeoutSeconds' needs to be a positive integer (set to: 0)")));
// set valid readTimeoutSeconds
authBuilder.withReadTimeoutSeconds(1);
List<GenericKafkaListener> listeners4 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners4));
assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'readTimeoutSeconds' needs to be a positive integer"))));
}
use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateDuplicatePorts.
@ParallelTest
public void testValidateDuplicatePorts() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
GenericKafkaListener listener2 = new GenericKafkaListenerBuilder().withName("listener2").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
GenericKafkaListener listener3 = new GenericKafkaListenerBuilder().withName("listener3").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
List<GenericKafkaListener> listeners = asList(listener1, listener2, listener3);
assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder("every listener needs to have a unique port number"));
}
Aggregations