use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
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;
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
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);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method mockContainerEventWithoutRandomName.
/**
* Mock a container event, without modifying the involved Pod's name. Avoid using this method
* unless it is necessary to check that a specific event (in terms of fields) is emitted.
*
* @see KubernetesInternalRuntimeTest#mockContainerEvent(String, String, String, String, String)
*/
private static PodEvent mockContainerEventWithoutRandomName(String podName, String reason, String message, String creationTimestamp, String lastTimestamp) {
final PodEvent event = mock(PodEvent.class);
when(event.getPodName()).thenReturn(podName);
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 che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method testRepublishContainerOutputAsMachineLogEvents.
@Test
public void testRepublishContainerOutputAsMachineLogEvents() throws Exception {
final MachineLogsPublisher logsPublisher = new MachineLogsPublisher(eventPublisher, machinesCache, IDENTITY);
final PodEvent out1 = mockContainerEventWithoutRandomName(WORKSPACE_POD_NAME, "Pulling", "pulling image", EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
final PodEvent out2 = mockContainerEventWithoutRandomName(WORKSPACE_POD_NAME, "Pulled", "image pulled", EVENT_CREATION_TIMESTAMP, getCurrentTimestampWithOneHourShiftAhead());
final ArgumentCaptor<RuntimeLogEvent> captor = ArgumentCaptor.forClass(RuntimeLogEvent.class);
internalRuntime.doStartMachine(serverResolver);
logsPublisher.handle(out1);
logsPublisher.handle(out2);
verify(eventService, atLeastOnce()).publish(captor.capture());
final ImmutableList<RuntimeLogEvent> machineLogs = ImmutableList.of(asRuntimeLogEvent(out1), asRuntimeLogEvent(out2));
assertTrue(captor.getAllValues().containsAll(machineLogs));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project che-server by eclipse-che.
the class KubernetesDeploymentsTest method shouldFallbackToFirstTimeStampIfLastTimeStampIsNull.
@Test
public void shouldFallbackToFirstTimeStampIfLastTimeStampIsNull() 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, 1);
Date nextYear = cal.getTime();
when(event.getFirstTimestamp()).thenReturn(PodEvents.convertDateToEventTimestamp(nextYear));
when(event.getLastTimestamp()).thenReturn(null);
// When
watcher.eventReceived(Watcher.Action.ADDED, event);
// Then
verify(event, times(1)).getLastTimestamp();
verify(event, times(1)).getFirstTimestamp();
ArgumentCaptor<PodEvent> captor = ArgumentCaptor.forClass(PodEvent.class);
verify(podEventHandler).handle(captor.capture());
PodEvent podEvent = captor.getValue();
assertEquals(podEvent.getLastTimestamp(), PodEvents.convertDateToEventTimestamp(nextYear));
}
Aggregations