Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed and added Tables unit tests. #22196

Merged
merged 7 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions sdk/tables/azure-data-tables/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Licensed under the MIT License.
<tag>HEAD</tag>
</scm>

<properties>
<jacoco.skip.coverage.check>true</jacoco.skip.coverage.check>
vcolin7 marked this conversation as resolved.
Show resolved Hide resolved
</properties>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ private Mono<Response<List<TableTransactionActionResponse>>> parseResponse(Trans
}

if (error != null || errorMessage != null) {
String message = "An operation within the batch failed, the transaction has been rolled back.";
String message = "An action within the operation failed, the transaction has been rolled back.";

if (failedAction != null) {
message += " The failed operation was: " + failedAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.credential.AzureNamedKeyCredential;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
Expand Down Expand Up @@ -73,6 +74,15 @@ public TableServiceVersion getServiceVersion() {
return client.getServiceVersion();
}

/**
* Gets the {@link HttpPipeline} powering this client.
*
* @return This client's {@link HttpPipeline}.
*/
HttpPipeline getHttpPipeline() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is not required.

return client.getHttpPipeline();
}

/**
* Generates an account SAS for the Azure Storage account using the specified
* {@link TableAccountSasSignatureValues}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
package com.azure.data.tables.implementation.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import java.util.ArrayList;
import java.util.List;

/** Table Service Properties. */
@JacksonXmlRootElement(localName = "StorageServiceProperties")
@Fluent
public final class TableServiceProperties {
/*
Expand All @@ -31,11 +37,20 @@ public final class TableServiceProperties {
@JsonProperty(value = "MinuteMetrics")
private Metrics minuteMetrics;

private static final class CorsWrapper {
@JacksonXmlProperty(localName = "CorsRule")
private final List<CorsRule> items;

@JsonCreator
private CorsWrapper(@JacksonXmlProperty(localName = "CorsRule") List<CorsRule> items) {
this.items = items;
}
}
/*
* The set of CORS rules.
*/
@JsonProperty(value = "Cors")
private List<CorsRule> cors;
private CorsWrapper cors;

/**
* Get the logging property: Azure Analytics Logging settings.
Expand Down Expand Up @@ -103,7 +118,11 @@ public TableServiceProperties setMinuteMetrics(Metrics minuteMetrics) {
* @return the cors value.
*/
public List<CorsRule> getCors() {
return this.cors;
if (this.cors == null) {
this.cors = new CorsWrapper(new ArrayList<CorsRule>());
}

return this.cors.items;
}

/**
Expand All @@ -113,7 +132,8 @@ public List<CorsRule> getCors() {
* @return the TableServiceProperties object itself.
*/
public TableServiceProperties setCors(List<CorsRule> cors) {
this.cors = cors;
this.cors = new CorsWrapper(cors);

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

/** Stats for the service. */
@JacksonXmlRootElement(localName = "StorageServiceStats")
@Fluent
public final class TableServiceStats {
vcolin7 marked this conversation as resolved.
Show resolved Hide resolved
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.azure.core.annotation.Immutable;

/**
* Defines an action to be included as part of a transactional batch operation.
* Defines an action to be included as part of a transactional operation.
*/
@Immutable
public final class TableTransactionAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package com.azure.data.tables.models;

/**
* The type of action to be executed on a {@link TableEntity} in a transactional batch operation.
* The type of action to be executed on a {@link TableEntity} in a transactional operation.
*/
public enum TableTransactionActionType {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,33 @@ public static void main(String[] args) {
.addProperty("Brand", "Crayola")
.addProperty("Color", "Red");
transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, firstEntity));
System.out.printf("Added create operation to transactional batch for entity with partition key: %s, and row "
+ "key: %s\n", partitionKey, firstEntityRowKey);
System.out.printf("Added create action for entity with partition key: %s, and row key: %s\n", partitionKey,
vcolin7 marked this conversation as resolved.
Show resolved Hide resolved
firstEntityRowKey);

TableEntity secondEntity = new TableEntity(partitionKey, secondEntityRowKey)
.addProperty("Brand", "Crayola")
.addProperty("Color", "Blue");
transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, secondEntity));
System.out.printf("Added create operation to transactional batch for entity with partition key: %s, and row "
+ "key: %s\n", partitionKey, secondEntityRowKey);
System.out.printf("Added create action for entity with partition key: %s, and row key: %s\n", partitionKey,
secondEntityRowKey);

// Now let's update a different entity.
String rowKeyForUpdate = "m003";
TableEntity entityToUpdate = new TableEntity(partitionKey, rowKeyForUpdate)
.addProperty("Brand", "Crayola")
.addProperty("Color", "Blue");
transactionActions.add(new TableTransactionAction(TableTransactionActionType.UPDATE_MERGE, entityToUpdate));
System.out.printf("Added update operation to transactional batch for entity with partition key: %s, and row "
+ "key: %s\n", partitionKey, rowKeyForUpdate);
System.out.printf("Added update action for entity with partition key: %s, and row key: %s\n", partitionKey,
rowKeyForUpdate);

// And delete another one.
String rowKeyForDelete = "m004";
TableEntity entityToDelete = new TableEntity(partitionKey, rowKeyForDelete)
.addProperty("Brand", "Crayola")
.addProperty("Color", "Blue");
transactionActions.add(new TableTransactionAction(TableTransactionActionType.DELETE, entityToDelete));
System.out.printf("Added delete operation to transactional batch for entity with partition key: %s, and row "
+ "key: %s\n", partitionKey, rowKeyForDelete);
System.out.printf("Added delete action for entity with partition key: %s, and row key: %s\n", partitionKey,
rowKeyForDelete);

// Finally, let's submit the batch of operations and inspect all the responses.
TableTransactionResult tableTransactionResult = tableClient.submitTransaction(transactionActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void createEntityWithAllSupportedDataTypesAsync() {
StepVerifier.create(tableClient.getEntityWithResponse(partitionKeyValue, rowKeyValue, null))
.assertNext(response -> {
final TableEntity entity = response.getValue();
Map<String, Object> properties = entity.getProperties();
final Map<String, Object> properties = entity.getProperties();
assertTrue(properties.get("BinaryTypeProperty") instanceof byte[]);
assertTrue(properties.get("BooleanTypeProperty") instanceof Boolean);
assertTrue(properties.get("DateTypeProperty") instanceof OffsetDateTime);
Expand Down Expand Up @@ -493,7 +493,7 @@ void getEntityWithResponseSubclassAsync() {
String s = "Test";
SampleEntity.Color color = SampleEntity.Color.GREEN;

Map<String, Object> props = new HashMap<>();
final Map<String, Object> props = new HashMap<>();
props.put("ByteField", bytes);
props.put("BooleanField", b);
props.put("DateTimeField", dateTime);
Expand Down Expand Up @@ -607,15 +607,14 @@ void updateEntityWithResponseSubclassAsync() {

StepVerifier.create(tableClient.getEntity(partitionKeyValue, rowKeyValue))
.assertNext(entity -> {
Map<String, Object> properties = entity.getProperties();
final Map<String, Object> properties = entity.getProperties();
assertTrue(properties.containsKey("SubclassProperty"));
assertEquals("UpdatedValue", properties.get("SubclassProperty"));
})
.verifyComplete();
}*/

@Test
@Tag("ListEntities")
void listEntitiesAsync() {
// Arrange
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -633,7 +632,6 @@ void listEntitiesAsync() {
}

@Test
@Tag("ListEntities")
void listEntitiesWithFilterAsync() {
// Arrange
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -656,7 +654,6 @@ void listEntitiesWithFilterAsync() {
}

@Test
@Tag("ListEntities")
void listEntitiesWithSelectAsync() {
// Arrange
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -683,7 +680,6 @@ void listEntitiesWithSelectAsync() {
}

@Test
@Tag("ListEntities")
void listEntitiesWithTopAsync() {
// Arrange
final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -705,7 +701,6 @@ void listEntitiesWithTopAsync() {

// Will not be supporting subclasses of TableEntity for the time being.
/*@Test
@Tag("ListEntities")
void listEntitiesSubclassAsync() {
// Arrange
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -723,7 +718,6 @@ void listEntitiesSubclassAsync() {
}*/

@Test
@Tag("Batch")
void submitTransactionAsync() {
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
String rowKeyValue = testResourceNamer.randomName("rowKey", 20);
Expand Down Expand Up @@ -765,7 +759,6 @@ void submitTransactionAsync() {
}

@Test
@Tag("Batch")
void submitTransactionAsyncAllActions() {
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
String rowKeyValueCreate = testResourceNamer.randomName("rowKey", 20);
Expand Down Expand Up @@ -825,7 +818,6 @@ void submitTransactionAsyncAllActions() {
}

@Test
@Tag("Batch")
void submitTransactionAsyncWithFailingAction() {
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
String rowKeyValue = testResourceNamer.randomName("rowKey", 20);
Expand All @@ -840,7 +832,7 @@ void submitTransactionAsyncWithFailingAction() {
// Act & Assert
StepVerifier.create(tableClient.submitTransactionWithResponse(transactionalBatch))
.expectErrorMatches(e -> e instanceof TableTransactionFailedException
&& e.getMessage().contains("An operation within the batch failed")
&& e.getMessage().contains("An action within the operation failed")
&& e.getMessage().contains("The failed operation was")
&& e.getMessage().contains("DeleteEntity")
&& e.getMessage().contains("partitionKey='" + partitionKeyValue)
Expand All @@ -849,7 +841,6 @@ void submitTransactionAsyncWithFailingAction() {
}

@Test
@Tag("Batch")
void submitTransactionAsyncWithSameRowKeys() {
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
String rowKeyValue = testResourceNamer.randomName("rowKey", 20);
Expand All @@ -863,7 +854,7 @@ void submitTransactionAsyncWithSameRowKeys() {
// Act & Assert
StepVerifier.create(tableClient.submitTransactionWithResponse(transactionalBatch))
.expectErrorMatches(e -> e instanceof TableTransactionFailedException
&& e.getMessage().contains("An operation within the batch failed")
&& e.getMessage().contains("An action within the operation failed")
&& e.getMessage().contains("The failed operation was")
&& e.getMessage().contains("CreateEntity")
&& e.getMessage().contains("partitionKey='" + partitionKeyValue)
Expand All @@ -872,7 +863,6 @@ void submitTransactionAsyncWithSameRowKeys() {
}

@Test
@Tag("Batch")
void submitTransactionAsyncWithDifferentPartitionKeys() {
String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20);
String partitionKeyValue2 = testResourceNamer.randomName("partitionKey", 20);
Expand All @@ -888,7 +878,7 @@ void submitTransactionAsyncWithDifferentPartitionKeys() {
// Act & Assert
StepVerifier.create(tableClient.submitTransactionWithResponse(transactionalBatch))
.expectErrorMatches(e -> e instanceof TableTransactionFailedException
&& e.getMessage().contains("An operation within the batch failed")
&& e.getMessage().contains("An action within the operation failed")
&& e.getMessage().contains("The failed operation was")
&& e.getMessage().contains("CreateEntity")
&& e.getMessage().contains("partitionKey='" + partitionKeyValue2)
Expand All @@ -897,7 +887,6 @@ void submitTransactionAsyncWithDifferentPartitionKeys() {
}

@Test
@Tag("SAS")
public void generateSasTokenWithMinimumParameters() {
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
final TableSasPermission permissions = TableSasPermission.parse("r");
Expand All @@ -923,7 +912,6 @@ public void generateSasTokenWithMinimumParameters() {
}

@Test
@Tag("SAS")
public void generateSasTokenWithAllParameters() {
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
final TableSasPermission permissions = TableSasPermission.parse("raud");
Expand Down Expand Up @@ -968,7 +956,6 @@ public void generateSasTokenWithAllParameters() {
}

@Test
@Tag("SAS")
public void canUseSasTokenToCreateValidTableClient() {
final OffsetDateTime expiryTime = OffsetDateTime.of(2021, 12, 12, 0, 0, 0, 0, ZoneOffset.UTC);
final TableSasPermission permissions = TableSasPermission.parse("a");
Expand Down
Loading