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

Deprecate methods and provide replacement for PutCursorAsync #396

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public async Task PutCollectionPropertyAsync_ShouldThrow_WhenCollectionDoesNotEx
{
var body = new PutCollectionPropertyBody
{
JournalSize = 313136,
//JournalSize = 313136,
WaitForSync = false
};
var exception = await Assert.ThrowsAsync<ApiErrorException>(async () =>
Expand Down
22 changes: 13 additions & 9 deletions arangodb-net-standard.Test/CursorApi/CursorApiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,50 +280,54 @@ public async Task PostCursorAsync_ShouldReturnResponseModelWithInterface()
}

[Fact]
public async Task PutCursorAsync_ShouldSucceed()
[Trait("ServerVersion", "3_8_PLUS")]
public async Task PostAdvanceCursorAsync_ShouldSucceed()
{
var response = await _cursorApi.PostCursorAsync<long>("FOR i IN 0..1000 RETURN i");
Assert.True(response.HasMore);

var nextResponse = await _cursorApi.PutCursorAsync<long>(response.Id);
var nextResponse = await _cursorApi.PostAdvanceCursorAsync<long>(response.Id);
Assert.False(nextResponse.HasMore);
Assert.Single(nextResponse.Result);
Assert.Equal(1000, nextResponse.Result.First());
Assert.Equal(HttpStatusCode.OK, nextResponse.Code);
}

[Fact]
public async Task PutCursorAsync_ShouldThrow_WhenCursorIsExhausted()
[Trait("ServerVersion", "3_8_PLUS")]
public async Task PostAdvanceCursorAsync_ShouldThrow_WhenCursorIsExhausted()
{
var response = await _cursorApi.PostCursorAsync<long>("FOR i IN 0..1000 RETURN i");
Assert.True(response.HasMore);

var nextResponse = await _cursorApi.PutCursorAsync<long>(response.Id);
var nextResponse = await _cursorApi.PostAdvanceCursorAsync<long>(response.Id);
Assert.False(nextResponse.HasMore);

await Assert.ThrowsAsync<ApiErrorException>(async () =>
await _cursorApi.PutCursorAsync<long>(response.Id));
await _cursorApi.PostAdvanceCursorAsync<long>(response.Id));
}

[Fact]
public async Task PutCursorAsync_ShouldThrow_WhenCursorDoesNotExist()
[Trait("ServerVersion", "3_8_PLUS")]
public async Task PostAdvanceCursorAsync_ShouldThrow_WhenCursorDoesNotExist()
{
var ex = await Assert.ThrowsAsync<ApiErrorException>(async () =>
await _cursorApi.PutCursorAsync<long>("nada"));
await _cursorApi.PostAdvanceCursorAsync<long>("nada"));

Assert.NotNull(ex.ApiError.ErrorMessage);
Assert.Equal(1600, ex.ApiError.ErrorNum);
Assert.Equal(HttpStatusCode.NotFound, ex.ApiError.Code);
}

[Fact]
public async Task PutCursorAsync_ShouldReturnResponseModelWithInterface()
[Trait("ServerVersion", "3_8_PLUS")]
public async Task PostAdvanceCursorAsync_ShouldReturnResponseModelWithInterface()
{
PostCursorResponse<int> postResponse =
await _cursorApi.PostCursorAsync<int>("FOR i IN 0..1500 RETURN i");

ICursorResponse<int> putResult =
await _cursorApi.PutCursorAsync<int>(postResponse.Id);
await _cursorApi.PostAdvanceCursorAsync<int>(postResponse.Id);

Assert.NotNull(putResult);
}
Expand Down
2 changes: 1 addition & 1 deletion arangodb-net-standard.Test/Docs/UsageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ await adb.Document.PostDocumentAsync(
var response = await adb.Cursor.PostCursorAsync<MyClassDocument>(
@"FOR doc IN MyCollection
FILTER doc.ItemNumber == 123456
RETURN doc");
RETURN doc", null);

MyClassDocument item = response.Result.First();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class GetCollectionFiguresResponse

public string Id { get; set; }

[System.Obsolete()]
public int IndexBuckets { get; set; }

public string Error { get; set; }
Expand All @@ -24,12 +25,15 @@ public class GetCollectionFiguresResponse

public int Status { get; set; }

[System.Obsolete()]
public int JournalSize { get; set; }

[System.Obsolete()]
public bool IsVolatile { get; set; }

public string Name { get; set; }

[System.Obsolete()]
public bool DoCompact { get; set; }

public bool IsSystem { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class GetCollectionPropertiesResponse
/// Whether or not the collection is compacted.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public bool DoCompact { get; set; }

/// <summary>
/// The maximal size of a journal or datafile in bytes.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public int JournalSize { get; set; }

/// <summary>
Expand All @@ -35,6 +37,7 @@ public class GetCollectionPropertiesResponse
/// If true then the collection data is kept in-memory only and not made persistent.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public bool IsVolatile { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public class GetCollectionRevisionResponse

public bool WaitForSync { get; set; }

[System.Obsolete()]
public int JournalSize { get; set; }

[System.Obsolete()]
public bool IsVolatile { get; set; }

public bool IsSystem { get; set; }

[System.Obsolete()]
public int IndexBuckets { get; set; }

public CollectionKeyOptions KeyOptions { get; set; }
Expand All @@ -43,6 +46,7 @@ public class GetCollectionRevisionResponse

public string Name { get; set; }

[System.Obsolete()]
public bool DoCompact { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PostCollectionBody
/// Whether or not the collection will be compacted (default is true).
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public bool? DoCompact { get; set; }

/// <summary>
Expand All @@ -32,6 +33,8 @@ public class PostCollectionBody
/// For example, 64 might be a sensible value for a collection with 100 000 000 documents.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
///
[System.Obsolete()]
public int? IndexBuckets { get; set; }

/// <summary>
Expand All @@ -53,6 +56,7 @@ public class PostCollectionBody
/// and not for data that cannot be re-created otherwise. (The default is false)
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public bool? IsVolatile { get; set; }

/// <summary>
Expand All @@ -62,6 +66,7 @@ public class PostCollectionBody
/// (The default is a configuration parameter)
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
[System.Obsolete()]
public long? JournalSize { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class PostCollectionResponse
/// The maximal size of a journal or datafile in bytes.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
///
[System.Obsolete()]
public long JournalSize { get; set; }

public PostCollectionResponseCollectionKeyOptions KeyOptions { get; set; }
Expand All @@ -53,6 +55,8 @@ public class PostCollectionResponse
/// Whether or not the collection is compacted.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
///
[System.Obsolete()]
public bool DoCompact { get; set; }

/// <summary>
Expand All @@ -65,13 +69,17 @@ public class PostCollectionResponse
/// The number of buckets into which indexes using a hash table are split.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
///
[System.Obsolete()]
public int IndexBuckets { get; set; }

/// <summary>
/// Deprecated.
/// If true then the collection data is kept in-memory only and not made persistent.
/// This option is meaningful for the MMFiles storage engine only.
/// </summary>
///
[System.Obsolete()]
public bool IsVolatile { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class PutCollectionPropertyBody
{
public bool? WaitForSync { get; set; }

[System.Obsolete()]
public long? JournalSize { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PutCollectionPropertyResponse

public bool WaitForSync { get; set; }

[System.Obsolete()]
public long JournalSize { get; set; }

public int Status { get; set; }
Expand All @@ -18,8 +19,10 @@ public class PutCollectionPropertyResponse

public bool IsSystem { get; set; }

[System.Obsolete()]
public bool IsVolatile { get; set; }

[System.Obsolete()]
public bool DoCompact { get; set; }

public CollectionKeyOptions KeyOptions { get; set; }
Expand All @@ -41,6 +44,7 @@ public class PutCollectionPropertyResponse

public string StatusString { get; set; }

[System.Obsolete()]
public int IndexBuckets { get; set; }
}
}
35 changes: 30 additions & 5 deletions arangodb-net-standard/CursorApi/CursorApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -127,8 +128,8 @@ public virtual async Task<PostCursorResponse<T>> PostCursorAsync<T>(
{
var content = GetContent(postCursorBody, new ApiClientSerializationOptions(true, true));
var headerCollection = GetHeaderCollection(headerProperties);
using (var response = await _client.PostAsync(_cursorApiPath,
content,
using (var response = await _client.PostAsync(_cursorApiPath,
content,
headerCollection,
token).ConfigureAwait(false))
{
Expand Down Expand Up @@ -174,11 +175,12 @@ public virtual async Task<DeleteCursorResponse> DeleteCursorAsync(string cursorI
/// <param name="cursorId">ID of the existing query cursor.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
[Obsolete("Use PostAdvanceCursorAsync.")]
public virtual async Task<PutCursorResponse<T>> PutCursorAsync<T>(string cursorId,
CancellationToken token = default)
{
string uri = _cursorApiPath + "/" + WebUtility.UrlEncode(cursorId);
using (var response = await _client.PutAsync(uri, new byte[0],null,token).ConfigureAwait(false))
using (var response = await _client.PutAsync(uri, new byte[0], null, token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
Expand All @@ -189,5 +191,28 @@ public virtual async Task<PutCursorResponse<T>> PutCursorAsync<T>(string cursorI
throw await GetApiErrorException(response).ConfigureAwait(false);
}
}

/// <summary>
/// Advances an existing query cursor and gets the next set of results.
/// Replaces <see cref="PutCursorAsync{T}(string, CancellationToken)"/>
/// </summary>
/// <param name="cursorIdentifier">The name / identifier of the existing cursor.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
public virtual async Task<PostCursorResponse<T>> PostAdvanceCursorAsync<T>(string cursorIdentifier, CancellationToken token = default)
{
using (var response = await _client.PostAsync(
requestUri: _cursorApiPath + $"/{WebUtility.UrlEncode(cursorIdentifier)}",
content: new byte[] { },
token: token).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return DeserializeJsonFromStream<PostCursorResponse<T>>(stream);
}
throw await GetApiErrorException(response).ConfigureAwait(false);
}
}
}
}
}
11 changes: 11 additions & 0 deletions arangodb-net-standard/CursorApi/ICursorApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ Task<PostCursorResponse<T>> PostCursorAsync<T>(
CursorHeaderProperties headerProperties = null,
CancellationToken token = default);

/// <summary>
/// Advances an existing query cursor and gets the next set of results.
/// Replaces <see cref="PutCursorAsync{T}(string, CancellationToken)"/>
/// </summary>
/// <param name="cursorIdentifier">The name / identifier of the existing cursor.</param>
/// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param>
/// <returns></returns>
Task<PostCursorResponse<T>> PostAdvanceCursorAsync<T>(
string cursorIdentifier,
CancellationToken token = default);

/// <summary>
/// Deletes an existing cursor and frees the resources associated with it.
/// DELETE /_api/cursor/{cursor-identifier}
Expand Down