use of com.google.cloud.video.livestream.v1.Event in project incubator-skywalking by apache.
the class EventHookCallbackTest method testEventCallbackHasRightFlow.
@Test
public void testEventCallbackHasRightFlow() throws Exception {
List<AlarmMessage> msgs = mockAlarmMessagesHasSingleElement();
EventHookCallback callback = new EventHookCallback(this.moduleManager);
when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(mockEventAnalyzerService);
// make sure current service be called.
callback.doAlarm(msgs);
verify(mockEventAnalyzerService).analyze(any(Event.class));
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
callback.doAlarm(msgs);
// Ensure that the current Event is properly constructed
ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
verify(eventAnalyzerService).analyze(argument.capture());
Event value = argument.getValue();
AlarmMessage msg = msgs.get(0);
assertEquals(msg.getName(), value.getSource().getService());
assertEquals("Alarm", value.getName());
assertEquals(msg.getAlarmMessage(), value.getMessage());
assertEquals(msg.getPeriod(), (value.getEndTime() - value.getStartTime()) / 1000 / 60);
}
use of com.google.cloud.video.livestream.v1.Event in project incubator-skywalking by apache.
the class EventHookCallbackTest method testRelationEventBeProperlyConstructed.
@Test
public void testRelationEventBeProperlyConstructed() {
List<AlarmMessage> msgs = mockAlarmMessagesHasSourceAndDest();
EventHookCallback callback = new EventHookCallback(this.moduleManager);
when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
callback.doAlarm(msgs);
ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
verify(eventAnalyzerService, times(2)).analyze(argument.capture());
List<Event> events = argument.getAllValues();
assertEquals(events.size(), 2);
Event sourceEvent = events.get(0);
Event destEvent = events.get(1);
AlarmMessage msg = msgs.get(0);
assertEquals(sourceEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId0()).getName());
assertEquals((sourceEvent.getEndTime() - sourceEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
assertEquals(destEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId1()).getName());
assertEquals((destEvent.getEndTime() - destEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
}
use of com.google.cloud.video.livestream.v1.Event in project java-docs-samples by GoogleCloudPlatform.
the class DeleteChannelEvent method deleteChannelEvent.
public static void deleteChannelEvent(String projectId, String location, String channelId, String eventId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
var deleteEventRequest = DeleteEventRequest.newBuilder().setName(EventName.of(projectId, location, channelId, eventId).toString()).build();
livestreamServiceClient.deleteEvent(deleteEventRequest);
System.out.println("Deleted channel event");
}
}
use of com.google.cloud.video.livestream.v1.Event in project java-docs-samples by GoogleCloudPlatform.
the class GetChannelEvent method getChannelEvent.
public static void getChannelEvent(String projectId, String location, String channelId, String eventId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
EventName name = EventName.of(projectId, location, channelId, eventId);
Event response = livestreamServiceClient.getEvent(name);
System.out.println("Channel event: " + response.getName());
}
}
use of com.google.cloud.video.livestream.v1.Event in project java-docs-samples by GoogleCloudPlatform.
the class ListChannelEvents method listChannelEvents.
public static void listChannelEvents(String projectId, String location, String channelId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (LivestreamServiceClient livestreamServiceClient = LivestreamServiceClient.create()) {
var listEventsRequest = ListEventsRequest.newBuilder().setParent(ChannelName.of(projectId, location, channelId).toString()).build();
LivestreamServiceClient.ListEventsPagedResponse response = livestreamServiceClient.listEvents(listEventsRequest);
System.out.println("Channel events:");
for (Event event : response.iterateAll()) {
System.out.println(event.getName());
}
}
}
Aggregations