-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Added CassandraTest #14886
Added CassandraTest #14886
Changes from all commits
580a574
8f33f66
faee5da
fe5a5f0
e1a1406
6157432
25c6f92
edaf70f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.CosmosDB.Models; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.ResourceManager.CosmosDB.Tests | ||
{ | ||
[TestFixture] | ||
public class CassandraResourcesOperationsTests : CosmosDBManagementClientBase | ||
{ | ||
protected string resourceGroupName; | ||
protected string databaseAccountName = "db12345"; | ||
protected string keyspaceName = "keyspaceName2510"; | ||
protected string keyspaceName2 = "keyspaceName22510"; | ||
protected string tableName = "tableName2510"; | ||
protected string cassandraThroughputType = "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces/throughputSettings"; | ||
protected int sampleThroughput = 700; | ||
|
||
public CassandraResourcesOperationsTests() | ||
: base(true) | ||
{ | ||
} | ||
|
||
[SetUp] | ||
public async Task ClearAndInitialize() | ||
{ | ||
if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback) | ||
{ | ||
InitializeClients(); | ||
resourceGroupName = Recording.GenerateAssetName(CosmosDBTestUtilities.ResourceGroupPrefix); | ||
await CosmosDBTestUtilities.TryRegisterResourceGroupAsync(ResourceGroupsOperations, CosmosDBTestUtilities.Location, resourceGroupName); | ||
} | ||
} | ||
|
||
[TearDown] | ||
public async Task CleanupResourceGroup() | ||
{ | ||
await CleanupResourceGroupsAsync(); | ||
} | ||
|
||
[TestCase] | ||
public async Task CassandraCRUDTestsAsync() | ||
{ | ||
var locations = new List<Location>(); | ||
Location loc = new Location(); | ||
loc.LocationName = CosmosDBTestUtilities.Location; | ||
loc.FailoverPriority = 0; | ||
loc.IsZoneRedundant = false; | ||
locations.Add(loc); | ||
|
||
DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations); | ||
databaseAccountCreateUpdateParameters.Location = CosmosDBTestUtilities.Location; | ||
databaseAccountCreateUpdateParameters.Capabilities.Add(new Capability("EnableCassandra")); | ||
databaseAccountCreateUpdateParameters.ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.Eventual); | ||
|
||
await WaitForCompletionAsync(await CosmosDBManagementClient.DatabaseAccounts.StartCreateOrUpdateAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters)); | ||
|
||
Task<Response> taskIsDatabaseNameExists = CosmosDBManagementClient.DatabaseAccounts.CheckNameExistsAsync(databaseAccountName); | ||
Response isDatabaseNameExists = taskIsDatabaseNameExists.ConfigureAwait(false).GetAwaiter().GetResult(); | ||
Assert.AreEqual(200, isDatabaseNameExists.Status); | ||
|
||
CassandraKeyspaceCreateUpdateParameters cassandraKeyspaceCreateUpdateParameters = new CassandraKeyspaceCreateUpdateParameters(new CassandraKeyspaceResource(keyspaceName), new CreateUpdateOptions()); | ||
|
||
var cassandraKeyspaceResponse = await WaitForCompletionAsync (await CosmosDBManagementClient.CassandraResources.StartCreateUpdateCassandraKeyspaceAsync(resourceGroupName, databaseAccountName, keyspaceName, cassandraKeyspaceCreateUpdateParameters)); | ||
|
||
CassandraKeyspaceGetResults cassandraKeyspaceGetResults = cassandraKeyspaceResponse.Value; | ||
|
||
Assert.NotNull(cassandraKeyspaceGetResults); | ||
Assert.AreEqual(keyspaceName, cassandraKeyspaceGetResults.Name); | ||
|
||
var cassandraKeyspaceResponse1 = await WaitForCompletionAsync(await CosmosDBManagementClient.CassandraResources.StartCreateUpdateCassandraKeyspaceAsync(resourceGroupName, databaseAccountName, keyspaceName, cassandraKeyspaceCreateUpdateParameters)); | ||
|
||
CassandraKeyspaceGetResults cassandraKeyspaceGetResults1 = cassandraKeyspaceResponse1.Value; | ||
Assert.NotNull(cassandraKeyspaceGetResults1); | ||
Assert.AreEqual(keyspaceName, cassandraKeyspaceGetResults1.Name); | ||
|
||
VerifyEqualCassandraDatabases(cassandraKeyspaceGetResults, cassandraKeyspaceGetResults1); | ||
|
||
CassandraKeyspaceCreateUpdateParameters cassandraKeyspaceCreateUpdateParameters2 = new CassandraKeyspaceCreateUpdateParameters(new CassandraKeyspaceResource(keyspaceName2), new CreateUpdateOptions(sampleThroughput, default)); | ||
|
||
var cassandraKeyspaceResponse2 = await WaitForCompletionAsync(await CosmosDBManagementClient.CassandraResources.StartCreateUpdateCassandraKeyspaceAsync(resourceGroupName, databaseAccountName, keyspaceName2, cassandraKeyspaceCreateUpdateParameters2)); | ||
|
||
CassandraKeyspaceGetResults cassandraKeyspaceGetResults2 = cassandraKeyspaceResponse2.Value; | ||
Assert.NotNull(cassandraKeyspaceGetResults2); | ||
Assert.AreEqual(keyspaceName2, cassandraKeyspaceGetResults2.Name); | ||
|
||
var keyspacesResponseTask = CosmosDBManagementClient.CassandraResources.ListCassandraKeyspacesAsync(resourceGroupName, databaseAccountName).ToEnumerableAsync(); | ||
List<CassandraKeyspaceGetResults> cassandraKeyspaces = keyspacesResponseTask.ConfigureAwait(false).GetAwaiter().GetResult(); | ||
|
||
Assert.NotNull(cassandraKeyspaces); | ||
|
||
var throughputResponse = CosmosDBManagementClient.CassandraResources.GetCassandraKeyspaceThroughputAsync(resourceGroupName, databaseAccountName, keyspaceName2); | ||
ThroughputSettingsGetResults throughputSettingsGetResults = throughputResponse.ConfigureAwait(false).GetAwaiter().GetResult(); | ||
Assert.NotNull(throughputSettingsGetResults); | ||
Assert.NotNull(throughputSettingsGetResults.Name); | ||
Assert.AreEqual(throughputSettingsGetResults.Resource.Throughput, sampleThroughput); | ||
Assert.AreEqual(cassandraThroughputType, throughputSettingsGetResults.Type); | ||
|
||
//TODO: Migrate To Manual and Autoscale tests from example: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2020-04-01/examples/CosmosDBCassandraTableMigrateToAutoscale.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a test I found from the example json that wasn't covered in Track 1. The method to MigrateToManual didn't seem to work, so I've left a comment in case we ever want to cover this test. I can also remove the TODO: if that's preferred. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What were the issues you were facing in MigrateToManual method ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am getting a 404 error for "Entity not found". This is how I'm trying to use the method: |
||
//var migrateKeyspace = await cosmosDBClient.CassandraResources.StartMigrateCassandraKeyspaceToManualThroughputAsync(resourceGroupName, databaseAccountName, keyspaceName); | ||
//var taskResponseMigrate = migrateKeyspace.WaitForCompletionAsync(); | ||
//var responseMigrate = taskResponseMigrate.ConfigureAwait(false).GetAwaiter().GetResult(); | ||
//Assert.AreEqual(responseMigrate.Value.Resource.MinimumThroughput, responseMigrate.Value.Resource.Throughput); | ||
|
||
CassandraSchema cassandraSchema = new CassandraSchema(new List<Column> { new Column { Name = "columnA", Type = "int" }, new Column { Name = "columnB", Type = "ascii" } }, new List<CassandraPartitionKey> { new CassandraPartitionKey { Name = "columnA" } }, new List<ClusterKey> { new ClusterKey { Name = "columnB", OrderBy = "Asc" } }); | ||
CassandraTableResource cassandraTableResource = new CassandraTableResource(tableName, default, cassandraSchema, default); | ||
CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters(cassandraTableResource, new CreateUpdateOptions()); | ||
|
||
Response<CassandraTableGetResults> cassandraResponse = await WaitForCompletionAsync(await CosmosDBManagementClient.CassandraResources.StartCreateUpdateCassandraTableAsync(resourceGroupName, databaseAccountName, keyspaceName, tableName, cassandraTableCreateUpdateParameters)); | ||
CassandraTableGetResults cassandraTableGetResults = cassandraResponse.Value; | ||
Assert.NotNull(cassandraTableGetResults); | ||
|
||
VerifyCassandraTableCreation(cassandraTableGetResults, cassandraTableCreateUpdateParameters); | ||
|
||
var cassandraPageableResultsTask = CosmosDBManagementClient.CassandraResources.ListCassandraTablesAsync(resourceGroupName, databaseAccountName, keyspaceName).ToEnumerableAsync(); | ||
List<CassandraTableGetResults> cassandraTables = cassandraPageableResultsTask.ConfigureAwait(false).GetAwaiter().GetResult(); | ||
Assert.NotNull(cassandraTables); | ||
} | ||
|
||
private void VerifyCassandraTableCreation(CassandraTableGetResults cassandraTableGetResults, CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters) | ||
{ | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Id, cassandraTableCreateUpdateParameters.Resource.Id); | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.Columns.Count, cassandraTableCreateUpdateParameters.Resource.Schema.Columns.Count); | ||
for (int i = 0; i < cassandraTableGetResults.Resource.Schema.Columns.Count; i++) | ||
{ | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.Columns[i].Name, cassandraTableCreateUpdateParameters.Resource.Schema.Columns[i].Name); | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.Columns[i].Type, cassandraTableCreateUpdateParameters.Resource.Schema.Columns[i].Type); | ||
} | ||
|
||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.ClusterKeys.Count, cassandraTableCreateUpdateParameters.Resource.Schema.ClusterKeys.Count); | ||
for (int i = 0; i < cassandraTableGetResults.Resource.Schema.ClusterKeys.Count; i++) | ||
{ | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.ClusterKeys[i].Name, cassandraTableCreateUpdateParameters.Resource.Schema.ClusterKeys[i].Name); | ||
} | ||
|
||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.PartitionKeys.Count, cassandraTableCreateUpdateParameters.Resource.Schema.PartitionKeys.Count); | ||
for (int i = 0; i < cassandraTableGetResults.Resource.Schema.PartitionKeys.Count; i++) | ||
{ | ||
Assert.AreEqual(cassandraTableGetResults.Resource.Schema.PartitionKeys[i].Name, cassandraTableCreateUpdateParameters.Resource.Schema.PartitionKeys[i].Name); | ||
} | ||
} | ||
|
||
private void VerifyEqualCassandraDatabases(CassandraKeyspaceGetResults expectedValue, CassandraKeyspaceGetResults actualValue) | ||
{ | ||
Assert.AreEqual(expectedValue.Id, actualValue.Id); | ||
Assert.AreEqual(expectedValue.Name, actualValue.Name); | ||
Assert.AreEqual(expectedValue.Location, actualValue.Location); | ||
Assert.AreEqual(expectedValue.Tags, actualValue.Tags); | ||
Assert.AreEqual(expectedValue.Type, actualValue.Type); | ||
|
||
Assert.AreEqual(expectedValue.Options, actualValue.Options); | ||
|
||
Assert.AreEqual(expectedValue.Resource.Id, actualValue.Resource.Id); | ||
Assert.AreEqual(expectedValue.Resource.Rid, actualValue.Resource.Rid); | ||
Assert.AreEqual(expectedValue.Resource.Ts, actualValue.Resource.Ts); | ||
Assert.AreEqual(expectedValue.Resource.Etag, actualValue.Resource.Etag); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may forgot to test 4 operations in keyspace:
MigrateToAutoscale
,MigrateToManualThroughput
.ThroughputGet
,ThroughputUpdate
Same in cassandra table tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests weren't in Track 1. The methods for these examples didn't seem to work, so I am not doing them for now. We can leave a TODO: comment if necessary. This way we can get back to it in the future if we end up needing these tests.