Search in sources :

Example 76 with Service

use of com.google.cloud.servicedirectory.v1.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 77 with Service

use of com.google.cloud.servicedirectory.v1.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)

Example 78 with Service

use of com.google.cloud.servicedirectory.v1.Service in project quarkus by quarkusio.

the class KnativeWithTrafficSplittingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Service.class, s -> {
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(s.getMetadata()).satisfies(m -> {
                    assertThat(m.getName()).isEqualTo("knative-with-traffic-splitting");
                });
                assertThat(spec.getTemplate()).satisfies(template -> {
                    assertThat(template.getMetadata().getName()).isEqualTo("my-revision");
                });
                assertThat(spec.getTraffic()).singleElement().satisfies(t -> {
                    assertThat(t.getPercent()).isEqualTo(80);
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) List(java.util.List) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Service(io.fabric8.knative.serving.v1.Service) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProdBuildResults(io.quarkus.test.ProdBuildResults) IOException(java.io.IOException) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest)

Example 79 with Service

use of com.google.cloud.servicedirectory.v1.Service in project quarkus by quarkusio.

the class KnativeWithRevisionAutoscalingTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
        Service service = (Service) i;
        assertThat(service.getMetadata().getName()).isEqualTo(NAME);
        // Issue: https://github.com/quarkusio/quarkus/issues/23832
        // assertThat(service.getSpec().getTemplate().getSpec().getContainerConcurrency()).isEqualTo(5);
        Map<String, String> annotations = service.getSpec().getTemplate().getMetadata().getAnnotations();
        assertThat(annotations).contains(entry("autoscaling.knative.dev/class", "kpa.autoscaling.knative.dev"));
        assertThat(annotations).contains(entry("autoscaling.knative.dev/metric", "cpu"));
        assertThat(annotations).contains(entry("autoscaling.knative.dev/target-utilization-percentage", "55"));
        assertThat(annotations).contains(entry("autoscaling.knative.dev/target", "80"));
    });
}
Also used : Path(java.nio.file.Path) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Service(io.fabric8.knative.serving.v1.Service) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) 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)

Example 80 with Service

use of com.google.cloud.servicedirectory.v1.Service in project quarkus by quarkusio.

the class KnativeWithSpecifiedContainerNameTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Service.class, s -> {
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(s.getMetadata()).satisfies(m -> {
                    assertThat(m.getName()).isEqualTo("kfoo");
                });
                assertThat(spec.getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> {
                    assertThat(container.getCommand()).contains("my-command");
                    assertThat(container.getName()).isEqualTo("kbar");
                    assertThat(container.getArgs()).containsExactly("A", "B");
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) List(java.util.List) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Service(io.fabric8.knative.serving.v1.Service) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProdBuildResults(io.quarkus.test.ProdBuildResults) IOException(java.io.IOException) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest)

Aggregations

Test (org.junit.jupiter.api.Test)33 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 Test (org.junit.Test)19 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)18 CoreException (org.eclipse.core.runtime.CoreException)18 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)15 AbstractMessage (com.google.protobuf.AbstractMessage)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)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 ArrayList (java.util.ArrayList)11 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)11 List (java.util.List)10 DisplayName (org.junit.jupiter.api.DisplayName)10