Search in sources :

Example 1 with GetDataEndpointResult

use of com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoUploaderClientTest method uploadStream_mockAckResponseCompleteWithNullCallback_taskClosed.

@Test
public void uploadStream_mockAckResponseCompleteWithNullCallback_taskClosed() throws InterruptedException {
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsFrontendClient", mockKvsFrontendClient));
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsDataClient", mockKvsDataClient));
    ArgumentCaptor<PutMediaAckResponseHandler> putMediaAckResponseArgumentCaptor = ArgumentCaptor.forClass(PutMediaAckResponseHandler.class);
    ArgumentCaptor<PutMediaRequest> putMediaRequestArgumentCaptor = ArgumentCaptor.forClass(PutMediaRequest.class);
    when(mockKvsFrontendClient.getDataEndpoint(any(GetDataEndpointRequest.class))).thenReturn(new GetDataEndpointResult().withDataEndpoint(DATA_ENDPOINT));
    // Since we make putMedia do nothing, so it won't end until we close it.
    Date dateNow = Date.from(Instant.now());
    new Thread(() -> {
        videoUploaderClient.uploadStream(inputStream, dateNow, null, null);
    }).start();
    // wait until task start
    while (!videoUploaderClient.isOpen()) {
        System.out.println("task is not running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    verify(mockKvsDataClient).putMedia(putMediaRequestArgumentCaptor.capture(), putMediaAckResponseArgumentCaptor.capture());
    AckEvent event = new AckEvent().withAckEventType(AckEventType.Values.PERSISTED).withFragmentTimecode(dateNow.getTime());
    putMediaAckResponseArgumentCaptor.getValue().onAckEvent(event);
    putMediaAckResponseArgumentCaptor.getValue().onComplete();
    // wait until task end
    while (videoUploaderClient.isOpen()) {
        System.out.println("task is running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    Assertions.assertFalse(videoUploaderClient.isOpen());
}
Also used : GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) PutMediaAckResponseHandler(com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler) PutMediaRequest(com.amazonaws.services.kinesisvideo.model.PutMediaRequest) Date(java.util.Date) AckEvent(com.amazonaws.services.kinesisvideo.model.AckEvent) Test(org.junit.jupiter.api.Test)

Example 2 with GetDataEndpointResult

use of com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoUploaderClientTest method uploadStream_mockAckResponseCompleteWithUploadCallback_taskClosed.

@Test
public void uploadStream_mockAckResponseCompleteWithUploadCallback_taskClosed() throws InterruptedException {
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsFrontendClient", mockKvsFrontendClient));
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsDataClient", mockKvsDataClient));
    ArgumentCaptor<PutMediaAckResponseHandler> putMediaAckResponseArgumentCaptor = ArgumentCaptor.forClass(PutMediaAckResponseHandler.class);
    ArgumentCaptor<PutMediaRequest> putMediaRequestArgumentCaptor = ArgumentCaptor.forClass(PutMediaRequest.class);
    when(mockKvsFrontendClient.getDataEndpoint(any(GetDataEndpointRequest.class))).thenReturn(new GetDataEndpointResult().withDataEndpoint(DATA_ENDPOINT));
    doNothing().when(mockKvsDataClient).putMedia(any(PutMediaRequest.class), any(PutMediaAckResponseHandler.class));
    // Since we make putMedia do nothing, so it won't end until we close it.
    Date dateNow = Date.from(Instant.now());
    final UploadCallBack uploadCallBack = new UploadCallBack(dateNow, edgeConnectorForKVSConfiguration);
    new Thread(() -> {
        videoUploaderClient.uploadStream(inputStream, dateNow, null, uploadCallBack);
    }).start();
    // wait until task start
    while (!videoUploaderClient.isOpen()) {
        System.out.println("task is not running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    verify(mockKvsDataClient).putMedia(putMediaRequestArgumentCaptor.capture(), putMediaAckResponseArgumentCaptor.capture());
    AckEvent event = new AckEvent().withAckEventType(AckEventType.Values.PERSISTED).withFragmentTimecode(dateNow.getTime());
    putMediaAckResponseArgumentCaptor.getValue().onAckEvent(event);
    putMediaAckResponseArgumentCaptor.getValue().onComplete();
    // wait until task end
    while (videoUploaderClient.isOpen()) {
        System.out.println("task is running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    Assertions.assertFalse(videoUploaderClient.isOpen());
}
Also used : GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) PutMediaAckResponseHandler(com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler) PutMediaRequest(com.amazonaws.services.kinesisvideo.model.PutMediaRequest) Date(java.util.Date) AckEvent(com.amazonaws.services.kinesisvideo.model.AckEvent) UploadCallBack(com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack) Test(org.junit.jupiter.api.Test)

Example 3 with GetDataEndpointResult

use of com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoUploaderClientTest method uploadHistoricalVideo_filesInTimePeriod_runCallbacks.

@Test
public void uploadHistoricalVideo_filesInTimePeriod_runCallbacks() throws InterruptedException {
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsFrontendClient", mockKvsFrontendClient));
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsDataClient", mockKvsDataClient));
    Assumptions.assumeTrue(tempVideoFilesPresent());
    final boolean[] isStatusChanged = { false };
    final Runnable statusChangedCallBack = () -> isStatusChanged[0] = true;
    UploadCallBack uploadCallBack = new UploadCallBack(Date.from(instantNow.minusSeconds(600)), edgeConnectorForKVSConfiguration);
    when(mockKvsFrontendClient.getDataEndpoint(any(GetDataEndpointRequest.class))).thenReturn(new GetDataEndpointResult().withDataEndpoint(DATA_ENDPOINT));
    doNothing().when(mockKvsDataClient).putMedia(any(PutMediaRequest.class), any(PutMediaAckResponseHandler.class));
    // Since we make putMedia do nothing, so it won't end until we close it.
    new Thread(() -> {
        videoUploaderClient.uploadHistoricalVideo(Date.from(instantNow.minusSeconds(600)), Date.from(instantNow.minusSeconds(200)), statusChangedCallBack, uploadCallBack);
    }).start();
    // wait until task start
    if (!videoUploaderClient.isOpen()) {
        System.out.println("task is not running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    videoUploaderClient.close();
    // wait until task end
    while (videoUploaderClient.isOpen()) {
        System.out.println("task is running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    Assertions.assertFalse(isStatusChanged[0]);
    Assertions.assertNull(uploadCallBack.getUploadingFile());
}
Also used : GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) PutMediaAckResponseHandler(com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler) PutMediaRequest(com.amazonaws.services.kinesisvideo.model.PutMediaRequest) UploadCallBack(com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack) Test(org.junit.jupiter.api.Test)

Example 4 with GetDataEndpointResult

use of com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoUploaderClientTest method uploadStream_mockAckResponseComplete_runCallbacks.

@Test
public void uploadStream_mockAckResponseComplete_runCallbacks() throws InterruptedException {
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsFrontendClient", mockKvsFrontendClient));
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsDataClient", mockKvsDataClient));
    final boolean[] isStatusChanged = { false };
    final Runnable statusChangedCallBack = () -> isStatusChanged[0] = true;
    final UploadCallBack uploadCallBack = new UploadCallBack(Date.from(Instant.now()), edgeConnectorForKVSConfiguration);
    ArgumentCaptor<PutMediaAckResponseHandler> putMediaAckResponseArgumentCaptor = ArgumentCaptor.forClass(PutMediaAckResponseHandler.class);
    ArgumentCaptor<PutMediaRequest> putMediaRequestArgumentCaptor = ArgumentCaptor.forClass(PutMediaRequest.class);
    when(mockKvsFrontendClient.getDataEndpoint(any(GetDataEndpointRequest.class))).thenReturn(new GetDataEndpointResult().withDataEndpoint(DATA_ENDPOINT));
    doNothing().when(mockKvsDataClient).putMedia(any(PutMediaRequest.class), any(PutMediaAckResponseHandler.class));
    when(this.edgeConnectorForKVSConfiguration.getStreamManager()).thenReturn(streamManager);
    when(streamManager.pushData(any(), any(), any(), any())).thenReturn(0L);
    // Since we make putMedia do nothing, so it won't end until we close it.
    new Thread(() -> {
        videoUploaderClient.uploadStream(inputStream, Date.from(Instant.now()), statusChangedCallBack, uploadCallBack);
    }).start();
    Thread.sleep(STATUS_CHANGED_TIME);
    // wait until task start
    while (!videoUploaderClient.isOpen()) {
        System.out.println("task is not running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    verify(mockKvsDataClient).putMedia(putMediaRequestArgumentCaptor.capture(), putMediaAckResponseArgumentCaptor.capture());
    AckEvent event = new AckEvent().withAckEventType(AckEventType.Values.PERSISTED);
    event.setFragmentTimecode(1L);
    putMediaAckResponseArgumentCaptor.getValue().onAckEvent(event);
    // Wait stream manager update values
    Thread.sleep(STATUS_CHANGED_TIME);
    putMediaAckResponseArgumentCaptor.getValue().onComplete();
    // wait until task end
    while (videoUploaderClient.isOpen()) {
        System.out.println("task is running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    Assertions.assertFalse(isStatusChanged[0]);
    verify(streamManager, times(1)).pushData(any(), any(), any(), any());
}
Also used : GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) PutMediaAckResponseHandler(com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler) PutMediaRequest(com.amazonaws.services.kinesisvideo.model.PutMediaRequest) AckEvent(com.amazonaws.services.kinesisvideo.model.AckEvent) UploadCallBack(com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack) Test(org.junit.jupiter.api.Test)

Example 5 with GetDataEndpointResult

use of com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class VideoUploaderClientTest method uploadStream_validInputs_runCallbacks.

@Test
public void uploadStream_validInputs_runCallbacks() throws InterruptedException {
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsFrontendClient", mockKvsFrontendClient));
    Assumptions.assumeTrue(setPrivateMember(videoUploaderClient, "kvsDataClient", mockKvsDataClient));
    final boolean[] isStatusChanged = { false };
    final Runnable statusChangedCallBack = () -> isStatusChanged[0] = true;
    final UploadCallBack uploadCallBack = new UploadCallBack(Date.from(Instant.now()), edgeConnectorForKVSConfiguration);
    when(mockKvsFrontendClient.getDataEndpoint(any(GetDataEndpointRequest.class))).thenReturn(new GetDataEndpointResult().withDataEndpoint(DATA_ENDPOINT));
    doNothing().when(mockKvsDataClient).putMedia(any(PutMediaRequest.class), any(PutMediaAckResponseHandler.class));
    // Since we make putMedia do nothing, so it won't end until we close it.
    new Thread(() -> {
        videoUploaderClient.uploadStream(inputStream, Date.from(Instant.now()), statusChangedCallBack, uploadCallBack);
    }).start();
    // wait until task start
    if (!videoUploaderClient.isOpen()) {
        System.out.println("task is not running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    videoUploaderClient.close();
    // wait until task end
    if (videoUploaderClient.isOpen()) {
        System.out.println("task is running");
        Thread.sleep(STATUS_CHANGED_TIME);
    }
    Assertions.assertFalse(isStatusChanged[0]);
    verify(streamManager, times(0)).pushData(any(), any(), any(), any());
}
Also used : GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) PutMediaAckResponseHandler(com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler) PutMediaRequest(com.amazonaws.services.kinesisvideo.model.PutMediaRequest) UploadCallBack(com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack) Test(org.junit.jupiter.api.Test)

Aggregations

GetDataEndpointRequest (com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest)8 GetDataEndpointResult (com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult)8 PutMediaAckResponseHandler (com.amazonaws.services.kinesisvideo.PutMediaAckResponseHandler)7 PutMediaRequest (com.amazonaws.services.kinesisvideo.model.PutMediaRequest)7 Test (org.junit.jupiter.api.Test)7 UploadCallBack (com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack)6 AckEvent (com.amazonaws.services.kinesisvideo.model.AckEvent)4 Date (java.util.Date)2 AmazonClientException (com.amazonaws.AmazonClientException)1 KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)1 AWSKinesisVideoClient (com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient)1 KvsStreamingException (com.aws.iot.edgeconnectorforkvs.videouploader.model.exceptions.KvsStreamingException)1