Search in sources :

Example 91 with Service

use of com.google.monitoring.v3.Service in project yakc by manusa.

the class ServiceIT method patchNamespacedService.

@Test
@DisplayName("patchNamespacedService, should patch labels of Service")
void patchNamespacedService() throws IOException {
    // When
    final Service result = KC.create(CoreV1Api.class).patchNamespacedService(serviceName, NAMESPACE, Service.builder().metadata(ObjectMeta.builder().putInLabels("patched", "label").build()).build()).get();
    // Then
    assertThat(result).isNotNull().extracting(Service::getMetadata).hasFieldOrPropertyWithValue("name", serviceName).extracting(ObjectMeta::getLabels).asInstanceOf(InstanceOfAssertFactories.MAP).hasSize(2).containsEntry("patched", "label");
}
Also used : Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 92 with Service

use of com.google.monitoring.v3.Service in project yakc by manusa.

the class ServiceIT method replaceNamespacedService.

@Test
@DisplayName("replaceNamespacedService, should replace existing Service's port")
void replaceNamespacedService() throws IOException {
    // Given
    final Service existingService = KC.create(CoreV1Api.class).readNamespacedService(serviceName, NAMESPACE).get();
    existingService.getSpec().getPorts().get(0).setTargetPort("http");
    // When
    final Service result = KC.create(CoreV1Api.class).replaceNamespacedService(serviceName, NAMESPACE, existingService).get();
    // Then
    assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.name", serviceName).extracting(Service::getSpec).extracting(ServiceSpec::getPorts).asList().hasSize(2).element(0).hasFieldOrPropertyWithValue("targetPort", "http");
}
Also used : ServiceSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec) Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 93 with Service

use of com.google.monitoring.v3.Service in project yakc by manusa.

the class ServiceIT method awaitCreateWatch.

@Test
@DisplayName("listNamespacedService.watch, should await for notification of newly created Service")
void awaitCreateWatch() throws IOException {
    // Given
    final AtomicBoolean hasError = new AtomicBoolean(false);
    final AtomicBoolean hasCompleted = new AtomicBoolean(false);
    // When
    final Disposable d = KC.create(CoreV1Api.class).listNamespacedService(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(serviceName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
    // Then
    assertThat(d).isNotNull();
    assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse();
    assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BeforeEach(org.junit.jupiter.api.BeforeEach) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) ClusterVersion(com.marcnuri.yakc.ClusterExecutionCondition.ClusterVersion) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) UUID(java.util.UUID) DisplayName(org.junit.jupiter.api.DisplayName) ServicePort(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServicePort) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Disposable(io.reactivex.disposables.Disposable) AfterEach(org.junit.jupiter.api.AfterEach) DeleteOptions(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions) NotFoundException(com.marcnuri.yakc.api.NotFoundException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Type(com.marcnuri.yakc.api.WatchEvent.Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 94 with Service

use of com.google.monitoring.v3.Service in project yakc by manusa.

the class ServiceLegacyIT method awaitCreateWatch.

@Test
@DisplayName("listNamespacedService.watch, should await for notification of newly created Service")
void awaitCreateWatch() throws IOException {
    // Given
    final AtomicBoolean hasError = new AtomicBoolean(false);
    final AtomicBoolean hasCompleted = new AtomicBoolean(false);
    // When
    final Disposable d = KC.create(CoreV1Api.class).listNamespacedService(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(serviceName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
    // Then
    assertThat(d).isNotNull();
    assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse();
    assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BeforeEach(org.junit.jupiter.api.BeforeEach) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceSpec(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) UUID(java.util.UUID) Status(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.Status) DisplayName(org.junit.jupiter.api.DisplayName) ServicePort(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServicePort) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Disposable(io.reactivex.disposables.Disposable) AfterEach(org.junit.jupiter.api.AfterEach) DeleteOptions(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.DeleteOptions) NotFoundException(com.marcnuri.yakc.api.NotFoundException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Service(com.marcnuri.yakc.model.io.k8s.api.core.v1.Service) Type(com.marcnuri.yakc.api.WatchEvent.Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 95 with Service

use of com.google.monitoring.v3.Service in project quarkus by quarkusio.

the class KnativeWithSecretConfigTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml"));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(h -> "RoleBinding".equals(h.getKind())).hasSize(2);
    assertThat(kubernetesList).filteredOn(h -> "ServiceAccount".equals(h.getKind())).singleElement().satisfies(s -> {
        assertThat(s.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("knative-with-secret-config");
        });
    });
    assertThat(kubernetesList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().isInstanceOf(Service.class).satisfies(s -> {
        assertThat(s.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("knative-with-secret-config");
        });
        assertThat(((Service) s).getSpec()).satisfies(serviceSpec -> {
            assertThat(serviceSpec.getTemplate()).satisfies(revisionTemplateSpec -> {
                assertThat(revisionTemplateSpec.getSpec()).satisfies(revisionSpec -> {
                    assertThat(revisionSpec.getServiceAccountName()).isEqualTo("knative-with-secret-config");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Service(io.fabric8.knative.serving.v1.Service) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.knative.serving.v1.Service) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)33 Test (org.junit.Test)30 Service (io.fabric8.knative.serving.v1.Service)28 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 AbstractMessage (com.google.protobuf.AbstractMessage)19 CoreException (org.eclipse.core.runtime.CoreException)18 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)16 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)16 HashMap (java.util.HashMap)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 ArrayList (java.util.ArrayList)12 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 StatusRuntimeException (io.grpc.StatusRuntimeException)11 ProdBuildResults (io.quarkus.test.ProdBuildResults)11 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)11 QuarkusProdModeTest (io.quarkus.test.QuarkusProdModeTest)11 Path (java.nio.file.Path)11