Search in sources :

Example 1 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testListLiveChannel.

@Test
public void testListLiveChannel() {
    final String liveChannelPrefix = "normal-list-live-channel";
    try {
        // create live channels
        for (int i = 0; i < 10; i++) {
            CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannelPrefix + i);
            ossClient.createLiveChannel(createLiveChannelRequest);
        }
        // default
        ListLiveChannelsRequest listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        LiveChannelListing liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() >= 10);
        Assert.assertNull(liveChannelListing.getPrefix());
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        // prefix
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 10);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // marker
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMarker(liveChannelPrefix + 5);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 4);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertEquals(liveChannelListing.getMarker(), liveChannelPrefix + 5);
        Assert.assertNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 100);
        Assert.assertFalse(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // marker
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMaxKeys(5);
        liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
        Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 5);
        Assert.assertEquals(liveChannelListing.getPrefix(), liveChannelPrefix);
        Assert.assertNull(liveChannelListing.getMarker());
        Assert.assertNotNull(liveChannelListing.getNextMarker());
        Assert.assertEquals(liveChannelListing.getMaxKeys(), 5);
        Assert.assertTrue(liveChannelListing.isTruncated());
        for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
            Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            Assert.assertEquals(liveChannel.getDescription(), "");
            Assert.assertEquals(liveChannel.getStatus(), LiveChannelStatus.Enabled);
            Assert.assertTrue(dateAfterValidator(liveChannel.getLastModified()));
            Assert.assertEquals(liveChannel.getPublishUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).startsWith("rtmp://"));
            Assert.assertTrue(liveChannel.getPublishUrls().get(0).indexOf("live/" + liveChannelPrefix) > -1);
            Assert.assertEquals(liveChannel.getPlayUrls().size(), 1);
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).startsWith("http://"));
            Assert.assertTrue(liveChannel.getPlayUrls().get(0).endsWith("/playlist.m3u8"));
        }
        // page
        listLiveChannelsRequest = new ListLiveChannelsRequest(bucketName);
        listLiveChannelsRequest.setPrefix(liveChannelPrefix);
        listLiveChannelsRequest.setMaxKeys(5);
        do {
            liveChannelListing = ossClient.listLiveChannels(listLiveChannelsRequest);
            Assert.assertTrue(liveChannelListing.getLiveChannels().size() == 5);
            for (LiveChannel liveChannel : liveChannelListing.getLiveChannels()) {
                Assert.assertTrue(liveChannel.getName().startsWith(liveChannelPrefix));
            }
            listLiveChannelsRequest.setMarker(liveChannelListing.getNextMarker());
        } while (liveChannelListing.isTruncated());
        // list all
        List<LiveChannel> liveChannels = ossClient.listLiveChannels(bucketName);
        Assert.assertTrue(liveChannels.size() >= 10);
        // delete live channels
        for (int i = 0; i < 10; i++) {
            ossClient.deleteLiveChannel(bucketName, liveChannelPrefix + i);
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) ListLiveChannelsRequest(com.aliyun.oss.model.ListLiveChannelsRequest) LiveChannelListing(com.aliyun.oss.model.LiveChannelListing) LiveChannel(com.aliyun.oss.model.LiveChannel) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 2 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelStatWithoutPushflow.

@Test
public void testGetLiveChannelStatWithoutPushflow() {
    final String liveChannel = "normal-get-live-channel-stat-without-pushflow";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        LiveChannelStat liveChannelStat = ossClient.getLiveChannelStat(bucketName, liveChannel);
        Assert.assertEquals(liveChannelStat.getPushflowStatus(), PushflowStatus.Idle);
        Assert.assertNull(liveChannelStat.getConnectedDate());
        Assert.assertNull(liveChannelStat.getRemoteAddress());
        Assert.assertNull(liveChannelStat.getVideoStat());
        Assert.assertNull(liveChannelStat.getAudioStat());
        Assert.assertEquals(liveChannelStat.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        liveChannelStat = ossClient.getLiveChannelStat(bucketName, liveChannel);
        Assert.assertEquals(liveChannelStat.getPushflowStatus(), PushflowStatus.Disabled);
        Assert.assertNull(liveChannelStat.getConnectedDate());
        Assert.assertNull(liveChannelStat.getRemoteAddress());
        Assert.assertNull(liveChannelStat.getVideoStat());
        Assert.assertNull(liveChannelStat.getAudioStat());
        Assert.assertEquals(liveChannelStat.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) LiveChannelStat(com.aliyun.oss.model.LiveChannelStat) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 3 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelHistoryWithoutPushflow.

@Test
public void testGetLiveChannelHistoryWithoutPushflow() {
    final String liveChannel = "normal-get-live-channel-history-without-pushflow";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        List<LiveRecord> liveRecords = ossClient.getLiveChannelHistory(bucketName, liveChannel);
        Assert.assertEquals(liveRecords.size(), 0);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : LiveRecord(com.aliyun.oss.model.LiveRecord) CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 4 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testSetLiveChannelStatusRepeated.

@Test
public void testSetLiveChannelStatusRepeated() {
    final String liveChannel = "normal-set-live-channel-status-repeated";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        // set disabled
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        LiveChannelInfo liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Disabled);
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        // set enabled
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Enabled);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Enabled);
        liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Enabled);
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        // set disabled
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Disabled);
        liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Disabled);
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        // set enabled
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Enabled);
        ossClient.setLiveChannelStatus(bucketName, liveChannel, LiveChannelStatus.Enabled);
        liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Enabled);
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : LiveChannelInfo(com.aliyun.oss.model.LiveChannelInfo) CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 5 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelInfo.

@Test
public void testGetLiveChannelInfo() {
    final String liveChannel = "normal-get-live-channel-info";
    final String liveChannelDesc = "my test live channel";
    try {
        LiveChannelTarget target = new LiveChannelTarget("HLS", 100, 99, "myplaylist.m3u8");
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel, liveChannelDesc, LiveChannelStatus.Enabled, target);
        ossClient.createLiveChannel(createLiveChannelRequest);
        LiveChannelInfo liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getDescription(), liveChannelDesc);
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Enabled);
        Assert.assertEquals(liveChannelInfo.getTarget().getType(), "HLS");
        Assert.assertEquals(liveChannelInfo.getTarget().getFragDuration(), 100);
        Assert.assertEquals(liveChannelInfo.getTarget().getFragCount(), 99);
        Assert.assertEquals(liveChannelInfo.getTarget().getPlaylistName(), "myplaylist.m3u8");
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : LiveChannelInfo(com.aliyun.oss.model.LiveChannelInfo) CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) LiveChannelTarget(com.aliyun.oss.model.LiveChannelTarget) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

OSSException (com.aliyun.oss.OSSException)14 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)14 ParseException (java.text.ParseException)13 Test (org.junit.Test)12 LiveChannelInfo (com.aliyun.oss.model.LiveChannelInfo)6 LiveChannelTarget (com.aliyun.oss.model.LiveChannelTarget)3 CreateLiveChannelResult (com.aliyun.oss.model.CreateLiveChannelResult)2 LiveChannelStat (com.aliyun.oss.model.LiveChannelStat)2 LiveRecord (com.aliyun.oss.model.LiveRecord)2 Ignore (org.junit.Ignore)2 ListLiveChannelsRequest (com.aliyun.oss.model.ListLiveChannelsRequest)1 LiveChannel (com.aliyun.oss.model.LiveChannel)1 LiveChannelListing (com.aliyun.oss.model.LiveChannelListing)1