public async Task Dictionary_with_empty_string_as_key_should_fail_bulk_insert_request() { var jsonRequestFactory = new HttpJsonRequestFactory(25); using (var store = NewRemoteDocumentStore()) { var url = String.Format("{0}/databases/{1}", store.Url, store.DefaultDatabase); using (ConnectionOptions.Expect100Continue(url)) { var operationUrl = "/bulkInsert?&operationId=" + Guid.NewGuid(); var createHttpJsonRequestParams = new CreateHttpJsonRequestParams(null, url + operationUrl, HttpMethods.Post, new OperationCredentials(String.Empty, CredentialCache.DefaultNetworkCredentials), new DocumentConvention()); var request = jsonRequestFactory.CreateHttpJsonRequest(createHttpJsonRequestParams); var response = await request.ExecuteRawRequestAsync((requestStream, tcs) => { using (var bufferedStream = new MemoryStream()) { long bytesWritten; WriteToBuffer(bufferedStream, out bytesWritten); var requestBinaryWriter = new BinaryWriter(requestStream); requestBinaryWriter.Write((int)bufferedStream.Position); bufferedStream.WriteTo(requestStream); requestStream.Flush(); tcs.TrySetResult(null); } }); Assert.Equal(422, (int)response.StatusCode); } } }
private async Task StartBulkInsertAsync(BulkInsertOptions options) { using (ConnectionOptions.Expect100Continue(operationClient.Url)) { var operationUrl = CreateOperationUrl(options); var token = await GetToken().ConfigureAwait(false); try { token = await ValidateThatWeCanUseAuthenticateTokens(token).ConfigureAwait(false); } catch (Exception e) { throw new InvalidOperationException("Could not authenticate token for bulk insert, if you are using ravendb in IIS make sure you have Anonymous Authentication enabled in the IIS configuration", e); } using (operationRequest = CreateOperationRequest(operationUrl, token)) { var cancellationToken = CreateCancellationToken(); var response = await operationRequest.ExecuteRawRequestAsync((stream, source) => Task.Factory.StartNew(() => { try { WriteQueueToServer(stream, options, cancellationToken); var x = source.TrySetResult(null); } catch (Exception e) { source.TrySetException(e); } }, TaskCreationOptions.LongRunning)).ConfigureAwait(false); await response.AssertNotFailingResponse(); long operationId; using (response) using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) using (var streamReader = new StreamReader(stream)) { var result = RavenJObject.Load(new JsonTextReader(streamReader)); operationId = result.Value <long>("OperationId"); } if (await IsOperationCompleted(operationId).ConfigureAwait(false)) { responseOperationId = operationId; } } } }
public IDisposable Continue100Scope() { return(ConnectionOptions.Expect100Continue(this.Url)); }
private async Task StartBatchOperation() { if (tempStream != null) { tempStream.Dispose(); } tempStream = new MemoryStream(); streamingStarted.Reset(); using (ConnectionOptions.Expect100Continue(ServerUrl)) { var authToken = await GetToken().ConfigureAwait(false); try { authToken = await ValidateThatWeCanUseAuthenticateTokens(authToken).ConfigureAwait(false); } catch (Exception e) { throw new InvalidOperationException("Could not authenticate token for bulk insert, if you are using ravendb in IIS make sure you have Anonymous Authentication enabled in the IIS configuration", e); } var requestUriString = string.Format("{0}/batch?operationId={1}", CounterStorageUrl, OperationId); using (var request = CreateHttpJsonRequest(requestUriString, HttpMethods.Post, true, true) .AddOperationHeader("Single-Use-Auth-Token", authToken)) { var token = cts.Token; var response = await request.ExecuteRawRequestAsync((stream, source) => Task.Factory.StartNew(() => { streamingStarted.Set(); try { ContinuouslyWriteQueueToServer(stream, token); source.TrySetResult(null); } catch (Exception e) { source.TrySetException(e); batchOperationTcs.SetException(e); } }, TaskCreationOptions.LongRunning)).ConfigureAwait(false); await response.AssertNotFailingResponse().ConfigureAwait(false); using (response) { using (var stream = await response.GetResponseStreamWithHttpDecompression().ConfigureAwait(false)) { var result = RavenJToken.TryLoad(stream); if (result == null) //precaution - should prevent NRE in case the crap hits the fan { throw new InvalidOperationException("Invalid response from server... maybe its not json?"); } serverOperationId = result.Value <long>("OperationId"); } } await IsOperationCompleted(serverOperationId).ConfigureAwait(false); batchOperationTcs.SetResult(true); } } }