use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
the class KubernetesDeploymentsTest method shouldHandleEventWithEmptyLastTimestampAndFirstTimestamp.
@Test
public void shouldHandleEventWithEmptyLastTimestampAndFirstTimestamp() throws Exception {
// Given
when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND);
kubernetesDeployments.watchEvents(podEventHandler);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, -1);
Date minuteAgo = cal.getTime();
Field f = KubernetesDeployments.class.getDeclaredField("watcherInitializationDate");
f.setAccessible(true);
f.set(kubernetesDeployments, minuteAgo);
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());
when(event.getLastTimestamp()).thenReturn(null);
when(event.getFirstTimestamp()).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();
assertNotNull(podEvent.getLastTimestamp());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
the class LogWatcherTest method executorIsCalledWhenAllIsSet.
@Test
public void executorIsCalledWhenAllIsSet() 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);
// then
verify(executor, times(1)).execute(any());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent in project devspaces-images by redhat-developer.
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());
}
Aggregations