Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ealsur committed Dec 10, 2019
1 parent 526797b commit 163e4ac
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public ChangeFeedProcessorBuilder WithLeaseContainer(Container leaseContainer)
if (this.leaseContainer != null) throw new InvalidOperationException("The builder already defined a lease container.");
if (this.LeaseStoreManager != null) throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");

this.leaseContainer = (ContainerCore)leaseContainer;
this.leaseContainer = (ContainerInlineCore)leaseContainer;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,7 @@ public override TransactionalBatch CreateTransactionalBatch(PartitionKey partiti
{
return this.container.CreateTransactionalBatch(partitionKey);
}

public static implicit operator ContainerCore(ContainerInlineCore containerInlineCore) => containerInlineCore.container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task InitializeAsync()
DatabaseResponse db = await this.cosmosClient.CreateDatabaseAsync(Guid.NewGuid().ToString());
PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
partitionKeyDefinition.Paths.Add("/Status");
this.cosmosContainer = (ContainerCore)await db.Database.CreateContainerAsync(new ContainerProperties() { Id = Guid.NewGuid().ToString(), PartitionKey = partitionKeyDefinition }, 10000);
this.cosmosContainer = (ContainerInlineCore)await db.Database.CreateContainerAsync(new ContainerProperties() { Id = Guid.NewGuid().ToString(), PartitionKey = partitionKeyDefinition }, 10000);
}

[TestCleanup]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task BatchOrderedAsync()
TestDoc replaceDoc = this.GetTestDocCopy(firstDoc);
replaceDoc.Cost += 20;

TransactionalBatchResponse batchResponse = await new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
TransactionalBatchResponse batchResponse = await new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItem(firstDoc)
.ReplaceItem(replaceDoc.Id, replaceDoc)
.ExecuteAsync();
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task BatchItemETagAsync()
IfMatchEtag = readResponse.ETag
};

TransactionalBatchResponse batchResponse = await new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
TransactionalBatchResponse batchResponse = await new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItem(testDocToCreate)
.ReplaceItem(testDocToReplace.Id, testDocToReplace, requestOptions: firstReplaceOptions)
.ExecuteAsync();
Expand All @@ -155,7 +155,7 @@ public async Task BatchItemETagAsync()
IfMatchEtag = BatchTestBase.Random.Next().ToString()
};

TransactionalBatchResponse batchResponse = await new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
TransactionalBatchResponse batchResponse = await new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.ReplaceItem(testDocToReplace.Id, testDocToReplace, requestOptions: replaceOptions)
.ExecuteAsync();

Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task BatchItemTimeToLiveAsync()
TestDoc testDocToUpsert = await BatchTestBase.CreateSchematizedTestDocAsync(container, this.PartitionKey1, ttlInSeconds: ttlInSeconds);
testDocToUpsert.Cost++;

BatchCore batch = (BatchCore)(new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
BatchCore batch = (BatchCore)(new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItemStream(
BatchTestBase.TestDocToStream(testDocToCreate, isSchematized),
BatchTestBase.GetBatchItemRequestOptions(testDocToCreate, isSchematized, ttlInSeconds: ttlInSeconds))
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task BatchLargerThanServerRequestAsync()

// Increase the doc size by a bit so all docs won't fit in one server request.
appxDocSize = (int)(appxDocSize * 1.05);
TransactionalBatch batch = new BatchCore((ContainerCore)container, new Cosmos.PartitionKey(this.PartitionKey1));
TransactionalBatch batch = new BatchCore((ContainerInlineCore)container, new Cosmos.PartitionKey(this.PartitionKey1));
for (int i = 0; i < operationCount; i++)
{
TestDoc doc = BatchTestBase.PopulateTestDoc(this.PartitionKey1, minDesiredSize: appxDocSize);
Expand All @@ -257,7 +257,7 @@ public async Task BatchWithTooManyOperationsAsync()
Container container = BatchTestBase.JsonContainer;
const int operationCount = Constants.MaxOperationsInDirectModeBatchRequest + 1;

TransactionalBatch batch = new BatchCore((ContainerCore)container, new Cosmos.PartitionKey(this.PartitionKey1));
TransactionalBatch batch = new BatchCore((ContainerInlineCore)container, new Cosmos.PartitionKey(this.PartitionKey1));
for (int i = 0; i < operationCount; i++)
{
batch.ReadItem("someId");
Expand All @@ -277,7 +277,7 @@ public async Task BatchServerResponseTooLargeAsync()

TestDoc doc = await BatchTestBase.CreateJsonTestDocAsync(container, this.PartitionKey1, appxDocSizeInBytes);

TransactionalBatch batch = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));
TransactionalBatch batch = new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));
for (int i = 0; i < operationCount; i++)
{
batch.ReadItem(doc.Id);
Expand All @@ -301,7 +301,7 @@ public async Task BatchReadsOnlyAsync()
Container container = BatchTestBase.JsonContainer;
await this.CreateJsonTestDocsAsync(container);

TransactionalBatchResponse batchResponse = await new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
TransactionalBatchResponse batchResponse = await new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.ReadItem(this.TestDocPk1ExistingA.Id)
.ReadItem(this.TestDocPk1ExistingB.Id)
.ReadItem(this.TestDocPk1ExistingC.Id)
Expand Down Expand Up @@ -346,7 +346,7 @@ private async Task<TransactionalBatchResponse> RunCrudAsync(bool isStream, bool
TransactionalBatchResponse batchResponse;
if (!isStream)
{
batchResponse = await new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
batchResponse = await new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItem(testDocToCreate)
.ReadItem(this.TestDocPk1ExistingC.Id)
.ReplaceItem(testDocToReplace.Id, testDocToReplace)
Expand All @@ -357,7 +357,7 @@ private async Task<TransactionalBatchResponse> RunCrudAsync(bool isStream, bool
}
else
{
BatchCore batch = (BatchCore)(new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
BatchCore batch = (BatchCore)(new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItemStream(
BatchTestBase.TestDocToStream(testDocToCreate, isSchematized),
BatchTestBase.GetBatchItemRequestOptions(testDocToCreate, isSchematized))
Expand Down Expand Up @@ -448,8 +448,8 @@ public async Task BatchRateLimitingAsync()

private async Task<TransactionalBatchResponse[]> RunTwoLargeBatchesAsync(Container container)
{
TransactionalBatch batch1 = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));
TransactionalBatch batch2 = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));
TransactionalBatch batch1 = new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));
TransactionalBatch batch2 = new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1));

for (int i = 0; i < Constants.MaxOperationsInDirectModeBatchRequest; i++)
{
Expand Down Expand Up @@ -576,7 +576,7 @@ private async Task<Container> RunWithErrorAsync(
TestDoc testDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1);
TestDoc anotherTestDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1);

TransactionalBatch batch = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
TransactionalBatch batch = new BatchCore((ContainerInlineCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1))
.CreateItem(testDocToCreate);

appendOperation(batch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static void InitializeDirectContainers()
},
throughput: 400).GetAwaiter().GetResult().Container;

BatchTestBase.PartitionKeyDefinition = ((ContainerCore)BatchTestBase.LowThroughputJsonContainer).GetPartitionKeyDefinitionAsync(CancellationToken.None).GetAwaiter().GetResult();
BatchTestBase.PartitionKeyDefinition = ((ContainerCore)(ContainerInlineCore)BatchTestBase.LowThroughputJsonContainer).GetPartitionKeyDefinitionAsync(CancellationToken.None).GetAwaiter().GetResult();

// Create a container with at least 2 physical partitions for effective cross-partition testing
BatchTestBase.JsonContainer = BatchTestBase.Database.CreateContainerAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public async Task ReplaceThroughputTest()
Assert.IsNotNull(readThroughput);

await container.ReplaceThroughputAsync(readThroughput.Value + 1000);
int? replaceThroughput = await ((ContainerCore)container).ReadThroughputAsync();
int? replaceThroughput = await ((ContainerCore)(ContainerInlineCore)container).ReadThroughputAsync();
Assert.IsNotNull(replaceThroughput);
Assert.AreEqual(readThroughput.Value + 1000, replaceThroughput);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public async Task TestInitialize()
throughput: 20000,
cancellationToken: this.cancellationToken);

this.Container = (ContainerCore)response;
this.LargerContainer = (ContainerCore)largerContainer;
this.Container = (ContainerInlineCore)response;
this.LargerContainer = (ContainerInlineCore)largerContainer;
}

[TestCleanup]
Expand All @@ -68,7 +68,7 @@ public async Task StandByFeedIterator()
int visitedPkRanges = 0;

await this.CreateRandomItems(this.Container, batchSize, randomPartitionKey: true);
ContainerCore itemsCore = (ContainerCore)this.Container;
ContainerCore itemsCore = this.Container;
FeedIterator feedIterator = itemsCore.GetStandByFeedIterator(requestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue });

while (feedIterator.HasMoreResults)
Expand Down Expand Up @@ -162,7 +162,7 @@ public async Task StandByFeedIterator_EmptyBeginning()
int pkRangesCount = (await this.Container.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.Container.LinkUri)).Count;
int visitedPkRanges = 0;

ContainerCore itemsCore = (ContainerCore)this.Container;
ContainerCore itemsCore = this.Container;
FeedIterator feedIterator = itemsCore.GetStandByFeedIterator();

while (feedIterator.HasMoreResults)
Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task StandByFeedIterator_WithInexistentRange()

string corruptedTokenSerialized = JsonConvert.SerializeObject(corruptedTokens);

ContainerCore itemsCore = (ContainerCore)this.Container;
ContainerCore itemsCore = this.Container;
FeedIterator setIteratorNew =
itemsCore.GetStandByFeedIterator(corruptedTokenSerialized);

Expand All @@ -241,7 +241,7 @@ public async Task StandByFeedIterator_WithInexistentRange()
public async Task StandByFeedIterator_WithMaxItemCount()
{
await this.CreateRandomItems(this.Container, 2, randomPartitionKey: true);
ContainerCore itemsCore = (ContainerCore)this.Container;
ContainerCore itemsCore = this.Container;
FeedIterator feedIterator = itemsCore.GetStandByFeedIterator(maxItemCount: 1, requestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue });

while (feedIterator.HasMoreResults)
Expand Down Expand Up @@ -276,7 +276,7 @@ public async Task StandByFeedIterator_NoFetchNext()
int expected = 25;
int iterations = 0;
await this.CreateRandomItems(this.Container, expected, randomPartitionKey: true);
ContainerCore itemsCore = (ContainerCore)this.Container;
ContainerCore itemsCore = this.Container;
string continuationToken = null;
int count = 0;
while (true)
Expand Down Expand Up @@ -334,7 +334,7 @@ await iterator.ReadNextAsync(this.cancellationToken))
public async Task GetChangeFeedTokensAsync_MatchesPkRanges()
{
int pkRangesCount = (await this.LargerContainer.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.LargerContainer.LinkUri)).Count;
ContainerCore itemsCore = (ContainerCore)this.LargerContainer;
ContainerCore itemsCore = this.LargerContainer;
IEnumerable<string> tokens = await itemsCore.GetChangeFeedTokensAsync();
Assert.AreEqual(pkRangesCount, tokens.Count());
}
Expand All @@ -343,7 +343,7 @@ public async Task GetChangeFeedTokensAsync_MatchesPkRanges()
public async Task GetChangeFeedTokensAsync_AllowsParallelProcessing()
{
int pkRangesCount = (await this.LargerContainer.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.LargerContainer.LinkUri)).Count;
ContainerCore itemsCore = (ContainerCore)this.LargerContainer;
ContainerCore itemsCore = this.LargerContainer;
IEnumerable<string> tokens = await itemsCore.GetChangeFeedTokensAsync();
Assert.IsTrue(pkRangesCount > 1, "Should have created a multi partition container.");
Assert.AreEqual(pkRangesCount, tokens.Count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public async Task NonPartitionKeyLookupCacheTest()

string dbName = Guid.NewGuid().ToString();
string containerName = Guid.NewGuid().ToString();
ContainerCore testContainer = (ContainerCore)client.GetContainer(dbName, containerName);
ContainerCore testContainer = (ContainerInlineCore)client.GetContainer(dbName, containerName);

int loopCount = 2;
for (int i = 0; i < loopCount; i++)
Expand Down Expand Up @@ -1031,7 +1031,7 @@ public async Task ItemEpkQuerySingleKeyRangeValidation()
id: Guid.NewGuid().ToString(),
partitionKeyPath: "/pk",
throughput: 15000);
container = (ContainerCore)containerResponse;
container = (ContainerInlineCore)containerResponse;

// Get all the partition key ranges to verify there is more than one partition
IRoutingMapProvider routingMapProvider = await this.cosmosClient.DocumentClient.GetPartitionKeyRangeCacheAsync();
Expand Down Expand Up @@ -1296,7 +1296,7 @@ public async Task ReadNonPartitionItemAsync()
"ReadNonPartition" + Guid.NewGuid());

await NonPartitionedContainerHelper.CreateItemInNonPartitionedContainer(fixedContainer, nonPartitionItemId);
await NonPartitionedContainerHelper.CreateUndefinedPartitionItem((ContainerCore)this.Container, undefinedPartitionItemId);
await NonPartitionedContainerHelper.CreateUndefinedPartitionItem((ContainerInlineCore)this.Container, undefinedPartitionItemId);

ContainerResponse containerResponse = await fixedContainer.ReadContainerAsync();
Assert.IsTrue(containerResponse.Resource.PartitionKey.Paths.Count > 0);
Expand Down Expand Up @@ -1637,7 +1637,7 @@ public async Task ContainterReCreateStatelessTest(bool operationBetweenRecreate,
string containerName = Guid.NewGuid().ToString();

db1 = await cc1.CreateDatabaseAsync(dbName);
ContainerCore container1 = (ContainerCore)await db1.CreateContainerAsync(containerName, "/id");
ContainerCore container1 = (ContainerInlineCore)await db1.CreateContainerAsync(containerName, "/id");

await operation(container1, HttpStatusCode.OK);

Expand All @@ -1658,7 +1658,7 @@ public async Task ContainterReCreateStatelessTest(bool operationBetweenRecreate,
}

// Re-create again
container1 = (ContainerCore)await db1.CreateContainerAsync(containerName, "/id");
container1 = (ContainerInlineCore)await db1.CreateContainerAsync(containerName, "/id");

// Read through client1
await operation(container1, HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task TestInitialize()
Assert.IsNotNull(response);
Assert.IsNotNull(response.Container);
Assert.IsNotNull(response.Resource);
this.Container = (ContainerCore)response;
this.Container = (ContainerInlineCore)response;

DocumentFeedResponse<PartitionKeyRange> pkRangesFeed = await this.cosmosClient.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.Container.LinkUri);
Assert.IsTrue(pkRangesFeed.Count > 1, "Refresh container throughput to have at-least > 1 pk-range");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task TestInitialize()
Assert.IsNotNull(response);
Assert.IsNotNull(response.Container);
Assert.IsNotNull(response.Resource);
this.Container = (ContainerCore)response;
this.Container = (ContainerInlineCore)response;
}

[TestCleanup]
Expand Down
Loading

0 comments on commit 163e4ac

Please sign in to comment.