use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntimeTest 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);
when(event.getContainerName()).thenReturn(CONTAINER_NAME_1);
when(event.getReason()).thenReturn(reason);
when(event.getMessage()).thenReturn(message);
when(event.getCreationTimeStamp()).thenReturn(creationTimestamp);
when(event.getLastTimestamp()).thenReturn(lastTimestamp);
return event;
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
the class KubernetesDeploymentsTest method shouldUseLastTimestampIfAvailable.
@Test
public void shouldUseLastTimestampIfAvailable() throws InfrastructureException {
// Given
when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND);
kubernetesDeployments.watchEvents(podEventHandler);
verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture());
Watcher<Event> watcher = eventWatcherCaptor.getValue();
Event event = mock(Event.class);
when(event.getInvolvedObject()).thenReturn(objectReference);
when(event.getMetadata()).thenReturn(new ObjectMeta());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, 2);
Date nextYear = cal.getTime();
when(event.getLastTimestamp()).thenReturn(PodEvents.convertDateToEventTimestamp(nextYear));
// When
watcher.eventReceived(Watcher.Action.ADDED, event);
// Then
verify(event, times(1)).getLastTimestamp();
verify(event, never()).getFirstTimestamp();
ArgumentCaptor<PodEvent> captor = ArgumentCaptor.forClass(PodEvent.class);
verify(podEventHandler).handle(captor.capture());
PodEvent podEvent = captor.getValue();
assertEquals(podEvent.getLastTimestamp(), PodEvents.convertDateToEventTimestamp(nextYear));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
the class LogWatcherTest method executorIsNotCalledAgainAfterCleanup.
@Test
public void executorIsNotCalledAgainAfterCleanup() throws InfrastructureException {
// given
LogWatcher logWatcher = new LogWatcher(clientFactory, eventsPublisher, WORKSPACE_ID, NAMESPACE, PODNAMES, executor, TIMEOUTS, LIMIT_BYTES);
logWatcher.addLogHandler(handler);
PodEvent podEvent = new PodEvent(POD, "container123", "Started", "someevenbettermessage", "123456789", "987654321");
// when
logWatcher.handle(podEvent);
logWatcher.close();
logWatcher.handle(podEvent);
// then
verify(executor, times(1)).execute(any());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
the class LogWatcherTest method executorIsNotCalledWhenReasonIsNotStarted.
@Test
public void executorIsNotCalledWhenReasonIsNotStarted() throws InfrastructureException {
// given
LogWatcher logWatcher = new LogWatcher(clientFactory, eventsPublisher, WORKSPACE_ID, NAMESPACE, PODNAMES, executor, TIMEOUTS, LIMIT_BYTES);
logWatcher.addLogHandler(handler);
PodEvent podEvent = new PodEvent(POD, "container123", "NotStarted", "someevenbettermessage", "123456789", "987654321");
// when
logWatcher.handle(podEvent);
// then
verify(executor, times(0)).execute(any());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
the class LogWatcherTest method executorIsCalledJustOnceWhenSameEventArriveAgain.
@Test
public void executorIsCalledJustOnceWhenSameEventArriveAgain() throws InfrastructureException {
// given
LogWatcher logWatcher = new LogWatcher(clientFactory, eventsPublisher, WORKSPACE_ID, NAMESPACE, PODNAMES, executor, TIMEOUTS, LIMIT_BYTES);
logWatcher.addLogHandler(handler);
PodEvent podEvent = new PodEvent(POD, "container123", "Started", "someevenbettermessage", "123456789", "987654321");
// when
logWatcher.handle(podEvent);
logWatcher.handle(podEvent);
// then
verify(executor, times(1)).execute(any());
}
Aggregations