Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #572 from jcookems/dev

Dev
  • Loading branch information...
commit b49d5f363179a7c9b38e9df51bf55f38c4d394b4 2 parents 2fe9360 + a744d2f
@jcookems jcookems authored
View
13 ...osoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java
@@ -15,7 +15,10 @@
package com.microsoft.windowsazure.services.media.models;
+import java.io.UnsupportedEncodingException;
import java.net.URI;
+import java.net.URLEncoder;
+import java.security.InvalidParameterException;
import javax.ws.rs.core.MultivaluedMap;
@@ -302,7 +305,15 @@ public static EntityDeleteOperation delete(String assetId) {
* the content key uri
* @return the entity action operation
*/
- public static EntityLinkOperation linkContentKey(String assetId, URI contentKeyUri) {
+ public static EntityLinkOperation linkContentKey(String assetId, String contentKeyId) {
+ String escapedContentKeyId = null;
+ try {
+ escapedContentKeyId = URLEncoder.encode(contentKeyId, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new InvalidParameterException("contentKeyId");
+ }
+ URI contentKeyUri = URI.create(String.format("ContentKeys('%s')", escapedContentKeyId));
return new EntityLinkOperation("Assets", assetId, "ContentKeys", contentKeyUri);
}
}
View
4 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Task.java
@@ -120,8 +120,8 @@ public CreateBatchOperation(String mediaProcessorId, String taskBody) {
* the options
* @return the creates the batch operation
*/
- public CreateBatchOperation setOptions(int options) {
- this.taskType.setOptions(options);
+ public CreateBatchOperation setOptions(TaskOption options) {
+ this.taskType.setOptions(options.getCode());
return this;
}
View
18 ...ure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java
@@ -17,11 +17,7 @@
import static org.junit.Assert.*;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -283,17 +279,9 @@ public void linkAssetContentKeySuccess() throws ServiceException, URISyntaxExcep
String contentKeyId = String.format("nb:kid:UUID:%s", UUID.randomUUID());
String encryptedContentKey = "dummyEncryptedContentKey";
service.create(ContentKey.create(contentKeyId, ContentKeyType.StorageEncryption, encryptedContentKey));
- String escapedContentKeyId;
- try {
- escapedContentKeyId = URLEncoder.encode(contentKeyId, "UTF-8");
- }
- catch (UnsupportedEncodingException e) {
- throw new InvalidParameterException(contentKeyId);
- }
- URI contentKeyUri = new URI(String.format("ContentKeys('%s')", escapedContentKeyId));
// Act
- service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyUri));
+ service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyId));
// Assert
@@ -305,14 +293,12 @@ public void linkAssetContentKeySuccess() throws ServiceException, URISyntaxExcep
@Test
public void linkAssetContentKeyInvalidIdFailed() throws ServiceException, URISyntaxException {
// Arrange
- URI invalidContentKeyUri = new URI("ContentKeys('nb%3akid%3aUUID%3ainvalidContentKeyId')");
// Act
expectedException.expect(ServiceException.class);
expectedException.expect(new ServiceExceptionMatcher(400));
- service.action(Asset.linkContentKey(validButNonexistAssetId, invalidContentKeyUri));
+ service.action(Asset.linkContentKey(validButNonexistAssetId, "nb:kid:UUID:invalidContentKeyId"));
// Assert
-
}
}
View
16 ...pi/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java
@@ -19,9 +19,6 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URLEncoder;
import java.security.Security;
import java.util.EnumSet;
import java.util.List;
@@ -108,12 +105,6 @@ private MediaProcessorInfo GetMediaProcessor(String mediaProcessorName) throws S
return null;
}
- private void linkContentKey(AssetInfo assetInfo, ContentKeyInfo contentKeyInfo) throws ServiceException,
- UnsupportedEncodingException {
- URI contentKeyUri = createContentKeyUri(contentKeyInfo.getId());
- service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyUri));
- }
-
private String getProtectionKey(String protectionKeyId) throws ServiceException {
String protectionKey = (String) service.action(ProtectionKey.getProtectionKey(protectionKeyId));
return protectionKey;
@@ -131,11 +122,6 @@ private AssetFileInfo uploadEncryptedAssetFile(AssetInfo assetInfo, LocatorInfo
return assetFileInfo;
}
- private URI createContentKeyUri(String contentKeyId) throws UnsupportedEncodingException {
- String escapedContentKeyId = URLEncoder.encode(contentKeyId, "UTF-8");
- return URI.create(String.format("ContentKeys('%s')", escapedContentKeyId));
- }
-
private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKeyType, String protectionKeyId,
String protectionKey) throws Exception {
UUID contentKeyIdUuid = UUID.randomUUID();
@@ -182,7 +168,7 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
protectionKey);
// link the content key with the asset.
- linkContentKey(assetInfo, contentKeyInfo);
+ service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyInfo.getId()));
// encrypt the file.
byte[] encryptedContent = EncryptionHelper.EncryptFile(smallWMVInputStream, aesKey, initializationVector);
View
80 ...zure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java
@@ -2,11 +2,15 @@
import static org.junit.Assert.*;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.EnumSet;
import java.util.List;
+import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -17,12 +21,15 @@
import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.media.models.AccessPolicy;
import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
+import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
import com.microsoft.windowsazure.services.media.models.Asset;
+import com.microsoft.windowsazure.services.media.models.AssetFile;
import com.microsoft.windowsazure.services.media.models.AssetInfo;
import com.microsoft.windowsazure.services.media.models.ContentKey;
import com.microsoft.windowsazure.services.media.models.ContentKeyInfo;
import com.microsoft.windowsazure.services.media.models.Job;
import com.microsoft.windowsazure.services.media.models.JobInfo;
+import com.microsoft.windowsazure.services.media.models.JobState;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.Locator;
import com.microsoft.windowsazure.services.media.models.LocatorInfo;
@@ -116,8 +123,18 @@ private static void removeAllTestAssets() {
try {
List<AssetInfo> listAssetsResult = service.list(Asset.list());
for (AssetInfo assetInfo : listAssetsResult) {
- if (assetInfo.getName().startsWith(testAssetPrefix)) {
- service.delete(Asset.delete(assetInfo.getId()));
+ try {
+ if (assetInfo.getName().startsWith(testAssetPrefix)) {
+ service.delete(Asset.delete(assetInfo.getId()));
+ }
+ else if (assetInfo.getName().startsWith("JobOutputAsset(")
+ && assetInfo.getName().contains(testJobPrefix)) {
+ // Delete the temp assets associated with Job results.
+ service.delete(Asset.delete(assetInfo.getId()));
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
}
}
}
@@ -145,8 +162,32 @@ private static void removeAllTestJobs() {
try {
ListResult<JobInfo> jobs = service.list(Job.list());
for (JobInfo job : jobs) {
- if (job.getName().startsWith(testAssetPrefix)) {
- service.delete(Job.delete(job.getId()));
+ if (job.getName().startsWith(testJobPrefix)) {
+ // Job can't be deleted when it's state is
+ // canceling, scheduled,queued or processing
+ try {
+ if (isJobBusy(job.getState())) {
+ service.action(Job.cancel(job.getId()));
+ job = service.get(Job.get(job.getId()));
+ }
+
+ int retryCounter = 0;
+ while (isJobBusy(job.getState()) && retryCounter < 10) {
+ Thread.sleep(2000);
+ job = service.get(Job.get(job.getId()));
+ retryCounter++;
+ }
+
+ if (!isJobBusy(job.getState())) {
+ service.delete(Job.delete(job.getId()));
+ }
+ else {
+ // Not much to do so except wait.
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
}
@@ -155,10 +196,32 @@ private static void removeAllTestJobs() {
}
}
+ private static boolean isJobBusy(JobState state) {
+ return state == JobState.Canceling || state == JobState.Scheduled || state == JobState.Queued
+ || state == JobState.Processing;
+ }
+
interface ComponentDelegate {
void verifyEquals(String message, Object expected, Object actual);
}
+ protected static AssetInfo setupAssetWithFile() throws ServiceException {
+ String name = UUID.randomUUID().toString();
+ String testBlobName = "test" + name + ".bin";
+ AssetInfo assetInfo = service.create(Asset.create().setName(testAssetPrefix + name));
+
+ AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create(testPolicyPrefix + name, 10,
+ EnumSet.of(AccessPolicyPermission.WRITE)));
+ LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5);
+ WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);
+ InputStream blobContent = new ByteArrayInputStream(new byte[] { 4, 8, 15, 16, 23, 42 });
+ blobWriter.createBlockBlob(testBlobName, blobContent);
+
+ service.action(AssetFile.createFileInfos(assetInfo.getId()));
+
+ return assetInfo;
+ }
+
protected static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes)
throws ServiceException {
@@ -209,6 +272,15 @@ protected static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetI
}
}
+ protected void assertEqualsNullEmpty(String message, String expected, String actual) {
+ if ((expected == null || expected.length() == 0) && (actual == null || actual.length() == 0)) {
+ // both nullOrEmpty, so match.
+ }
+ else {
+ assertEquals(message, expected, actual);
+ }
+ }
+
protected void assertDateApproxEquals(Date expected, Date actual) {
assertDateApproxEquals("", expected, actual);
}
View
54 ...azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java
@@ -17,30 +17,21 @@
import static org.junit.Assert.*;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
-import java.util.EnumSet;
import java.util.List;
-import java.util.UUID;
import org.junit.BeforeClass;
import org.junit.Test;
import com.microsoft.windowsazure.services.core.ServiceException;
-import com.microsoft.windowsazure.services.media.models.AccessPolicy;
-import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
-import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
import com.microsoft.windowsazure.services.media.models.Asset;
-import com.microsoft.windowsazure.services.media.models.AssetFile;
import com.microsoft.windowsazure.services.media.models.AssetInfo;
import com.microsoft.windowsazure.services.media.models.ErrorDetail;
import com.microsoft.windowsazure.services.media.models.Job;
import com.microsoft.windowsazure.services.media.models.JobInfo;
import com.microsoft.windowsazure.services.media.models.JobState;
import com.microsoft.windowsazure.services.media.models.ListResult;
-import com.microsoft.windowsazure.services.media.models.LocatorInfo;
import com.microsoft.windowsazure.services.media.models.Task;
import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation;
import com.microsoft.windowsazure.services.media.models.TaskInfo;
@@ -48,7 +39,6 @@
public class JobIntegrationTest extends IntegrationTestBase {
private static AssetInfo assetInfo;
- private static final byte[] testBlobData = new byte[] { 4, 8, 15, 16, 23, 42 };
private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) {
verifyJobProperties(message, expected.getName(), expected.getPriority(), expected.getRunningDuration(),
@@ -79,15 +69,6 @@ private void verifyJobProperties(String message, String testName, Integer priori
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/531
}
- private void assertEqualsNullEmpty(String message, String expected, String actual) {
- if ((expected == null || expected.length() == 0) && (actual == null || actual.length() == 0)) {
- // both nullOrEmpty, so match.
- }
- else {
- assertEquals(message, expected, actual);
- }
- }
-
private JobInfo createJob(String name) throws ServiceException {
return service.create(Job.create().setName(name).setPriority(3).addInputMediaAsset(assetInfo.getId())
.addTaskCreator(getTaskCreator(0)));
@@ -104,23 +85,11 @@ private CreateBatchOperation getTaskCreator(int outputAssetPosition) {
@BeforeClass
public static void setup() throws Exception {
IntegrationTestBase.setup();
-
- String name = UUID.randomUUID().toString();
- String testBlobName = "test" + name + ".bin";
- assetInfo = service.create(Asset.create().setName(testAssetPrefix + name));
-
- AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create(testPolicyPrefix + name, 10,
- EnumSet.of(AccessPolicyPermission.WRITE)));
- LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5);
- WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);
- InputStream blobContent = new ByteArrayInputStream(testBlobData);
- blobWriter.createBlockBlob(testBlobName, blobContent);
-
- service.action(AssetFile.createFileInfos(assetInfo.getId()));
+ assetInfo = setupAssetWithFile();
}
@Test
- public void createJobSuccess() throws Exception {
+ public void createJobSuccess() throws ServiceException {
// Arrange
String name = testJobPrefix + "createJobSuccess";
int priority = 3;
@@ -142,7 +111,7 @@ public void createJobSuccess() throws Exception {
}
@Test
- public void createJobTwoTasksSuccess() throws Exception {
+ public void createJobTwoTasksSuccess() throws ServiceException {
// Arrange
String name = testJobPrefix + "createJobSuccess";
int priority = 3;
@@ -167,7 +136,7 @@ public void createJobTwoTasksSuccess() throws Exception {
}
@Test
- public void getJobSuccess() throws Exception {
+ public void getJobSuccess() throws ServiceException {
// Arrange
String name = testJobPrefix + "getJobSuccess";
int priority = 3;
@@ -231,7 +200,7 @@ public void canListJobsWithOptions() throws ServiceException {
}
@Test
- public void cancelJobSuccess() throws Exception {
+ public void cancelJobSuccess() throws ServiceException {
// Arrange
JobInfo jobInfo = createJob(testJobPrefix + "cancelJobSuccess");
@@ -257,13 +226,16 @@ public void cancelJobFailedWithInvalidId() throws ServiceException {
}
@Test
- public void deleteJobSuccess() throws ServiceException {
+ public void deleteJobSuccess() throws ServiceException, InterruptedException {
// Arrange
JobInfo jobInfo = createJob(testJobPrefix + "deleteJobSuccess");
service.action(Job.cancel(jobInfo.getId()));
JobInfo cancellingJobInfo = service.get(Job.get(jobInfo.getId()));
- while (cancellingJobInfo.getState() == JobState.Canceling) {
+ int retryCounter = 0;
+ while (cancellingJobInfo.getState() == JobState.Canceling && retryCounter < 10) {
+ Thread.sleep(2000);
cancellingJobInfo = service.get(Job.get(jobInfo.getId()));
+ retryCounter++;
}
// Act
@@ -326,9 +298,11 @@ public void canGetErrorDetailsFromTask() throws Exception {
.addTaskCreator(getTaskCreator(0)));
JobInfo currentJobInfo = actualJob;
- while (currentJobInfo.getState().getCode() < 3) {
+ int retryCounter = 0;
+ while (currentJobInfo.getState().getCode() < 3 && retryCounter < 10) {
+ Thread.sleep(10000);
currentJobInfo = service.get(Job.get(actualJob.getId()));
- Thread.sleep(3000);
+ retryCounter++;
}
ListResult<TaskInfo> tasks = service.list(Task.list(actualJob.getTasksLink()));
View
298 ...zure-api/src/test/java/com/microsoft/windowsazure/services/media/TaskIntegrationTest.java
@@ -0,0 +1,298 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.microsoft.windowsazure.services.media;
+
+import static org.junit.Assert.*;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.microsoft.windowsazure.services.core.ServiceException;
+import com.microsoft.windowsazure.services.media.models.Asset;
+import com.microsoft.windowsazure.services.media.models.AssetInfo;
+import com.microsoft.windowsazure.services.media.models.Job;
+import com.microsoft.windowsazure.services.media.models.Job.Creator;
+import com.microsoft.windowsazure.services.media.models.JobInfo;
+import com.microsoft.windowsazure.services.media.models.JobState;
+import com.microsoft.windowsazure.services.media.models.ListResult;
+import com.microsoft.windowsazure.services.media.models.Task;
+import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation;
+import com.microsoft.windowsazure.services.media.models.TaskInfo;
+import com.microsoft.windowsazure.services.media.models.TaskOption;
+import com.microsoft.windowsazure.services.media.models.TaskState;
+import com.sun.jersey.core.util.Base64;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+
+public class TaskIntegrationTest extends IntegrationTestBase {
+ private static AssetInfo assetInfo;
+ private Creator jobCreator;
+
+ private static final String commonMediaProcessorId = "nb:mpid:UUID:2f381738-c504-4e4a-a38e-d199e207fcd5";
+ private static final String commonConfiguration = "H.264 256k DSL CBR";
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ IntegrationTestBase.setup();
+ assetInfo = setupAssetWithFile();
+ }
+
+ @Before
+ public void instanceSetup() {
+ this.jobCreator = Job.create().setName(testJobPrefix + UUID.randomUUID().toString()).setPriority(3)
+ .addInputMediaAsset(assetInfo.getId());
+ }
+
+ @Test
+ public void createTaskSuccess() throws ServiceException, UnsupportedEncodingException {
+ // Arrange
+
+ // Required
+ String mediaProcessorId = commonMediaProcessorId;
+ String taskBody = constructTaskBody(0);
+
+ // Optional parameters
+ String configuration = new String(Base64.encode(commonConfiguration), "UTF8");
+ String name = "My encoding Task " + UUID.randomUUID().toString();
+ int priority = 0;
+ TaskOption options = TaskOption.ProtectedConfiguration;
+ // Use a fake id, to simulate real use.
+ String encryptionKeyId = "nb:kid:UUID:" + UUID.randomUUID().toString();
+ String encryptionScheme = "ConfigurationEncryption";
+ String encryptionVersion = "1.0";
+ // Use a trivial vector, 16 bytes of zeros, base-64 encoded.
+ String initializationVector = new String(Base64.encode(new byte[16]), "UTF8");
+
+ CreateBatchOperation taskCreator = Task.create(mediaProcessorId, taskBody).setConfiguration(configuration)
+ .setName(name).setPriority(priority).setOptions(options).setEncryptionKeyId(encryptionKeyId)
+ .setEncryptionScheme(encryptionScheme).setEncryptionVersion(encryptionVersion)
+ .setInitializationVector(initializationVector);
+ jobCreator.addTaskCreator(taskCreator);
+
+ // Act
+ JobInfo job = service.create(jobCreator);
+ List<TaskInfo> taskInfos = service.list(Task.list(job.getTasksLink()));
+
+ // Assert
+ assertEquals("taskInfos count", 1, taskInfos.size());
+ verifyTaskPropertiesJustStarted("taskInfo", mediaProcessorId, options, taskBody, configuration, name, priority,
+ encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, taskInfos.get(0));
+ }
+
+ @Test
+ public void createTwoTasksSuccess() throws ServiceException {
+ // Arrange
+
+ // Required
+ String mediaProcessorId = commonMediaProcessorId;
+ String[] taskBodies = new String[] { constructTaskBody(0), constructTaskBody(1) };
+
+ // Optional parameters
+ String configuration = commonConfiguration;
+ String baseName = "My encoding Task " + UUID.randomUUID().toString();
+ String[] suffixes = new String[] { " 1", " 2" };
+ int priority = 0;
+ TaskOption options = TaskOption.None;
+
+ List<CreateBatchOperation> taskCreators = new ArrayList<CreateBatchOperation>();
+
+ for (int i = 0; i < taskBodies.length; i++) {
+ CreateBatchOperation taskCreator = Task.create(mediaProcessorId, taskBodies[i])
+ .setConfiguration(configuration).setName(baseName + suffixes[i]);
+ taskCreators.add(taskCreator);
+ jobCreator.addTaskCreator(taskCreator);
+ }
+
+ // Act
+ JobInfo job = service.create(jobCreator);
+ List<TaskInfo> taskInfos = service.list(Task.list(job.getTasksLink()));
+
+ // Assert
+ assertEquals("taskInfos count", taskCreators.size(), taskInfos.size());
+ for (int i = 0; i < taskCreators.size(); i++) {
+ verifyTaskPropertiesJustStartedNoEncryption("taskInfo", mediaProcessorId, options, taskBodies[i],
+ configuration, baseName + suffixes[i], priority, taskInfos.get(i));
+ }
+ }
+
+ @Test
+ public void canListTasksWithOptions() throws ServiceException {
+ // Arrange
+ String mediaProcessorId = commonMediaProcessorId;
+ String configuration = commonConfiguration;
+ String[] taskNameSuffixes = new String[] { "A", "B", "C", "D" };
+ String baseName = "My encoding Task " + UUID.randomUUID().toString();
+ int taskCounter = 0;
+ for (String suffix : taskNameSuffixes) {
+ CreateBatchOperation taskCreator = Task.create(mediaProcessorId, constructTaskBody(taskCounter++))
+ .setConfiguration(configuration).setName(baseName + suffix);
+ jobCreator.addTaskCreator(taskCreator);
+ }
+
+ service.create(jobCreator);
+
+ // Act
+ MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl();
+ queryParameters.add("$filter", "startswith(Name, '" + baseName + "') eq true");
+ ListResult<TaskInfo> listTaskResult1 = service.list(Task.list(queryParameters));
+
+ queryParameters.add("$top", "2");
+ ListResult<TaskInfo> listTaskResult2 = service.list(Task.list(queryParameters));
+
+ // Assert
+ assertEquals("listTaskResult1.size", 4, listTaskResult1.size());
+ assertEquals("listTaskResult2.size", 2, listTaskResult2.size());
+ }
+
+ @Test
+ public void cancelTaskSuccess() throws ServiceException, InterruptedException {
+ // Arrange
+ String mediaProcessorId = commonMediaProcessorId;
+ String taskBody = constructTaskBody(0);
+ String configuration = commonConfiguration;
+ String name = "My encoding Task " + UUID.randomUUID().toString();
+ CreateBatchOperation taskCreator = Task.create(mediaProcessorId, taskBody).setConfiguration(configuration)
+ .setName(name);
+ jobCreator.addTaskCreator(taskCreator);
+
+ JobInfo jobInfo = service.create(jobCreator);
+
+ // Act
+ service.action(Job.cancel(jobInfo.getId()));
+ JobInfo cancellingJobInfo = service.get(Job.get(jobInfo.getId()));
+ while (cancellingJobInfo.getState() == JobState.Canceling) {
+ Thread.sleep(2000);
+ cancellingJobInfo = service.get(Job.get(jobInfo.getId()));
+ }
+
+ //Assert
+ List<TaskInfo> taskInfos = service.list(Task.list(cancellingJobInfo.getTasksLink()));
+ for (TaskInfo taskInfo : taskInfos) {
+ // Replace with enums
+ // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/522
+ verifyTaskPropertiesNoEncryption("canceled task", mediaProcessorId, TaskOption.None, taskBody,
+ configuration, name, 0, new Date(), null, 0.0, 0.0, null, TaskState.Canceled, taskInfo);
+ }
+ }
+
+ private void verifyTaskProperties(String message, String mediaProcessorId, TaskOption options, String taskBody,
+ String configuration, String name, int priority, String encryptionKeyId, String encryptionScheme,
+ String encryptionVersion, String initializationVector, Date endTime, String errorDetails, double progress,
+ double runningDuration, Date startTime, TaskState state, TaskInfo actual) throws ServiceException {
+ assertNotNull(message, actual);
+ assertNotNull(message + " id", actual.getId());
+
+ // Required fields
+ assertEquals(message + " getMediaProcessorId", mediaProcessorId, actual.getMediaProcessorId());
+ assertEquals(message + " getOptions", options, actual.getOptions());
+ assertEquals(message + " getTaskBody", taskBody, actual.getTaskBody());
+
+ // Optional fields
+ assertEquals(message + " getConfiguration", configuration, actual.getConfiguration());
+ assertEquals(message + " getName", name, actual.getName());
+ assertEquals(message + " getPriority", priority, actual.getPriority().intValue());
+
+ // Optional encryption fields
+ assertEqualsNullEmpty(message + " getEncryptionKeyId", encryptionKeyId, actual.getEncryptionKeyId());
+ assertEqualsNullEmpty(message + " getEncryptionScheme", encryptionScheme, actual.getEncryptionScheme());
+ assertEqualsNullEmpty(message + " getEncryptionVersion", encryptionVersion, actual.getEncryptionVersion());
+ assertEqualsNullEmpty(message + " getInitializationVector", initializationVector,
+ actual.getInitializationVector());
+
+ // Read-only fields
+ assertDateApproxEquals(message + " getEndTime", endTime, actual.getEndTime());
+ assertNotNull(message + " getErrorDetails", actual.getErrorDetails());
+ assertEquals(message + " getErrorDetails.size", 0, actual.getErrorDetails().size());
+
+ // TODO: Add tests for Historical events when added
+ // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/494
+
+ ListResult<AssetInfo> inputAssets = service.list(Asset.list(actual.getInputAssetsLink()));
+ ListResult<AssetInfo> outputAssets = service.list(Asset.list(actual.getOutputAssetsLink()));
+
+ assertEquals(message + " inputAssets.size", 1, inputAssets.size());
+ assertEquals(message + " inputAssets.get(0).getId", assetInfo.getId(), inputAssets.get(0).getId());
+
+ assertEquals(message + " outputAssets.size", 1, outputAssets.size());
+ // Because this is a new asset, there is not much else to test
+ assertTrue(message + " outputAssets.get(0).getId != assetInfo.getId",
+ !assetInfo.getId().equals(outputAssets.get(0).getId()));
+
+ assertEquals(message + " getProgress", progress, actual.getProgress().doubleValue(), 0.01);
+ assertEquals(message + " getRunningDuration", runningDuration, actual.getRunningDuration(), 0.01);
+ assertDateApproxEquals(message + " getStartTime", startTime, actual.getStartTime());
+ assertEquals(message + " getState", state, actual.getState());
+
+ // Note: The PerfMessage is not validated because it is server generated.
+ }
+
+ private void verifyTaskPropertiesJustStarted(String message, String mediaProcessorId, TaskOption options,
+ String taskBody, String configuration, String name, int priority, String encryptionKeyId,
+ String encryptionScheme, String encryptionVersion, String initializationVector, TaskInfo actual)
+ throws ServiceException {
+
+ // Read-only
+ Date endTime = null;
+ String errorDetails = null;
+ double progress = 0.0;
+ int runningDuration = 0;
+ Date startTime = null;
+ TaskState state = TaskState.None;
+
+ verifyTaskProperties(message, mediaProcessorId, options, taskBody, configuration, name, priority,
+ encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, endTime, errorDetails,
+ progress, runningDuration, startTime, state, actual);
+ }
+
+ private void verifyTaskPropertiesJustStartedNoEncryption(String message, String mediaProcessorId,
+ TaskOption options, String taskBody, String configuration, String name, int priority, TaskInfo actual)
+ throws ServiceException {
+ String encryptionKeyId = null;
+ String encryptionScheme = null;
+ String encryptionVersion = null;
+ String initializationVector = null;
+
+ verifyTaskPropertiesJustStarted(message, mediaProcessorId, options, taskBody, configuration, name, priority,
+ encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, actual);
+ }
+
+ private void verifyTaskPropertiesNoEncryption(String message, String mediaProcessorId, TaskOption options,
+ String taskBody, String configuration, String name, int priority, Date endTime, String errorDetails,
+ double progress, double runningDuration, Date startTime, TaskState state, TaskInfo actual)
+ throws ServiceException {
+ String encryptionKeyId = null;
+ String encryptionScheme = null;
+ String encryptionVersion = null;
+ String initializationVector = null;
+
+ verifyTaskProperties(message, mediaProcessorId, options, taskBody, configuration, name, priority,
+ encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, endTime, errorDetails,
+ progress, runningDuration, startTime, state, actual);
+ }
+
+ private String constructTaskBody(int outputIndex) {
+ return "<taskBody><inputAsset>JobInputAsset(0)</inputAsset>" + "<outputAsset>JobOutputAsset(" + outputIndex
+ + ")</outputAsset></taskBody>";
+ }
+}
View
6 ...src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java
@@ -106,7 +106,7 @@ public void createJob() throws Exception {
wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles());
signalSetupFinished();
- String jobName = "my job createJob";
+ String jobName = "my job createJob" + UUID.randomUUID().toString();
JobInfo job = wrapper.createJob(jobName, asset, createTasks());
validator.validateJob(job, jobName, asset, createTasks());
}
@@ -116,13 +116,13 @@ public void transformAsset() throws Exception {
signalSetupStarting();
AssetInfo asset = wrapper.createAsset(testAssetPrefix + "transformAsset", AssetOption.None);
wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles());
- String jobName = "my job transformAsset";
+ String jobName = "my job transformAsset" + UUID.randomUUID().toString();
JobInfo job = wrapper.createJob(jobName, asset, createTasks());
signalSetupFinished();
waitForJobToFinish(job);
List<AssetInfo> outputAssets = wrapper.getJobOutputMediaAssets(job);
- validator.validateOutputAssets(outputAssets);
+ validator.validateOutputAssets(outputAssets, getTestAssetFiles().keys());
}
private void waitForJobToFinish(JobInfo job) throws InterruptedException, ServiceException {
View
17 ...i/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java
@@ -23,6 +23,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
@@ -147,14 +148,16 @@ public void validateJob(JobInfo job, String name, AssetInfo asset, List<Task.Cre
// assertEquals("outputAssets.size()", createTasks.size(), outputAssets.size());
}
- public void validateOutputAssets(List<AssetInfo> outputAssets) throws ServiceException {
- // TODO: Uncomment when fixed:
- // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508
+ public void validateOutputAssets(List<AssetInfo> outputAssets, Enumeration<String> enumeration) {
+ assertNotNull("outputAssets", outputAssets);
+ for (AssetInfo asset : outputAssets) {
- // assertNotNull("outputAssets", outputAssets);
- // for (AssetInfo asset : outputAssets) {
- // this.validateAsset(asset, null, null);
- // }
+ assertNotNull("asset", asset);
+ assertNotNull("asset.getId", asset.getId());
+ assertFalse("asset.getId != ''", "".equals(asset.getId()));
+ assertEquals("asset.state", AssetState.Initialized, asset.getState());
+ assertEquals("asset.getOptions", AssetOption.None, asset.getOptions());
+ }
}
// This method is needed because there can be a delay before a new read locator
Please sign in to comment.
Something went wrong with that request. Please try again.