Search in sources :

Example 36 with PodEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.

the class UnrecoverablePodEventListenerTest method testHandleRegularEvent.

@Test
public void testHandleRegularEvent() throws Exception {
    // given
    final PodEvent regularEvent = mockContainerEvent(WORKSPACE_POD_NAME, "Pulling", "pulling image", EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
    // when
    unrecoverableEventListener.handle(regularEvent);
    // then
    verify(unrecoverableEventConsumer, never()).accept(any());
}
Also used : PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) Test(org.testng.annotations.Test)

Example 37 with PodEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.

the class UnrecoverablePodEventListenerTest method testDoNotHandleUnrecoverableEventFromNonWorkspacePod.

@Test
public void testDoNotHandleUnrecoverableEventFromNonWorkspacePod() throws Exception {
    // given
    final String unrecoverableEventMessage = "Failed to pull image eclipse/che-server:nightly-centos";
    final PodEvent unrecoverableEvent = mockContainerEvent("NonWorkspacePod", "Pulling", unrecoverableEventMessage, EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
    // when
    unrecoverableEventListener.handle(unrecoverableEvent);
    // then
    verify(unrecoverableEventConsumer, never()).accept(any());
}
Also used : PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) Test(org.testng.annotations.Test)

Example 38 with PodEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.

the class UnrecoverablePodEventListenerTest method mockContainerEvent.

/**
 * Mock a container event, as though it was triggered by the OpenShift API. As workspace Pods are
 * created indirectly through deployments, they are given generated names with the provided name
 * as a root. <br>
 * Use this method in a test to ensure that tested code manages this fact correctly. For example,
 * code such as unrecoverable events handling cannot directly look at an event's pod name and
 * compare it to the internal representation, and so must confirm the event is relevant in some
 * other way.
 */
private static PodEvent mockContainerEvent(String podName, String reason, String message, String creationTimestamp, String lastTimestamp) {
    final PodEvent event = mock(PodEvent.class);
    when(event.getPodName()).thenReturn(podName + POD_NAME_RANDOM_SUFFIX);
    lenient().when(event.getContainerName()).thenReturn(CONTAINER_NAME_1);
    lenient().when(event.getReason()).thenReturn(reason);
    lenient().when(event.getMessage()).thenReturn(message);
    lenient().when(event.getCreationTimeStamp()).thenReturn(creationTimestamp);
    lenient().when(event.getLastTimestamp()).thenReturn(lastTimestamp);
    return event;
}
Also used : PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent)

Example 39 with PodEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.

the class UnrecoverablePodEventListenerTest method testHandleUnrecoverableEventByReason.

@Test
public void testHandleUnrecoverableEventByReason() throws Exception {
    // given
    String unrecoverableEventReason = "Failed Mount";
    PodEvent unrecoverableEvent = mockContainerEvent(WORKSPACE_POD_NAME, unrecoverableEventReason, "Failed to mount volume 'claim-che-workspace'", EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
    // when
    unrecoverableEventListener.handle(unrecoverableEvent);
    // then
    verify(unrecoverableEventConsumer).accept(unrecoverableEvent);
}
Also used : PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) Test(org.testng.annotations.Test)

Example 40 with PodEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.

the class UnrecoverablePodEventListenerTest method testHandleUnrecoverableEventByMessage.

@Test
public void testHandleUnrecoverableEventByMessage() throws Exception {
    // given
    String unrecoverableEventMessage = "Failed to pull image eclipse/che-server:nightly-centos";
    PodEvent unrecoverableEvent = mockContainerEvent(WORKSPACE_POD_NAME, "Pulling", unrecoverableEventMessage, EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
    // when
    unrecoverableEventListener.handle(unrecoverableEvent);
    // then
    verify(unrecoverableEventConsumer).accept(unrecoverableEvent);
}
Also used : PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) Test(org.testng.annotations.Test)

Aggregations

PodEvent (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent)40 Test (org.testng.annotations.Test)32 Event (io.fabric8.kubernetes.api.model.Event)8 Date (java.util.Date)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)6 Calendar (java.util.Calendar)6 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)2 ObjectReference (io.fabric8.kubernetes.api.model.ObjectReference)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 Field (java.lang.reflect.Field)2 ParseException (java.text.ParseException)2 Matcher (java.util.regex.Matcher)2 RuntimeLogEvent (org.eclipse.che.api.workspace.shared.dto.event.RuntimeLogEvent)2 KubernetesInfrastructureException (org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException)2 LogWatcher (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatcher)2