Skip to content

Commit

Permalink
Fixed and added Tables unit tests. (#22196)
Browse files Browse the repository at this point in the history
* Fixed Tables tests and added tests for sync clients. Modified generated classes to fit the XML shape the service expects.

* Updated and added test recordings.

* Removed flag that made the JaCoCo coverage check get skipped.

* Fixed CheckStyle issues. Applied PR feedback.

* Removed unused import.

* Removed @tag annotations on tests. Removed references to 'batch' and 'operation' in samples and error messages.

* Applied more PR feedback.
  • Loading branch information
vcolin7 authored Jun 10, 2021
1 parent 511847b commit c73bdf1
Show file tree
Hide file tree
Showing 62 changed files with 4,818 additions and 172 deletions.
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>
</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() {
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 {
/*
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,
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
Loading

0 comments on commit c73bdf1

Please sign in to comment.