private static void ValidateCopier(int bufferLength, bool inputSync, int inputDelayInMs, bool outputSync, int outputDelayInMs) { byte[] buffer = new byte[bufferLength]; new Random().NextBytes(buffer); int expectedCallCount = buffer.Length / Constants.DefaultBufferSize; int totalDelayInMs = (expectedCallCount + 1) * inputDelayInMs + expectedCallCount * outputDelayInMs; DataValidationStream input = new DataValidationStream(buffer, inputSync, inputDelayInMs); DataValidationStream output = new DataValidationStream(buffer, outputSync, outputDelayInMs); OperationContext opContext = new OperationContext(); ExecutionState <NullType> state = new ExecutionState <NullType>(null, new NoRetry(), opContext); StreamDescriptor copyState = new StreamDescriptor(); using (ManualResetEvent waitHandle = new ManualResetEvent(false)) { input.WriteToAsync(output, null, null, false, state, opContext, copyState, _ => { waitHandle.Set(); }); Assert.IsTrue(waitHandle.WaitOne(totalDelayInMs + 10 * 1000)); } Assert.AreEqual(output.LastException, state.ExceptionRef); if (output.LastException != null) { throw output.LastException; } Assert.AreEqual(buffer.Length, copyState.Length); Assert.AreEqual(expectedCallCount + 1, input.ReadCallCount); Assert.AreEqual(expectedCallCount, output.WriteCallCount); }
private static void ValidateCopier(int bufferLength, bool inputSync, int inputDelayInMs, bool outputSync, int outputDelayInMs) { byte[] buffer = new byte[bufferLength]; new Random().NextBytes(buffer); int expectedCallCount = buffer.Length / Constants.DefaultBufferSize; int totalDelayInMs = (expectedCallCount + 1) * inputDelayInMs + expectedCallCount * outputDelayInMs; DataValidationStream input = new DataValidationStream(buffer, inputSync, inputDelayInMs); DataValidationStream output = new DataValidationStream(buffer, outputSync, outputDelayInMs); OperationContext opContext = new OperationContext(); ExecutionState<NullType> state = new ExecutionState<NullType>(null, new NoRetry(), opContext); StreamDescriptor copyState = new StreamDescriptor(); using (ManualResetEvent waitHandle = new ManualResetEvent(false)) { input.WriteToAsync(output, null, null, false, state, opContext, copyState, _ => { waitHandle.Set(); }); Assert.IsTrue(waitHandle.WaitOne(totalDelayInMs + 10 * 1000)); } Assert.AreEqual(output.LastException, state.ExceptionRef); if (output.LastException != null) { throw output.LastException; } Assert.AreEqual(buffer.Length, copyState.Length); Assert.AreEqual(expectedCallCount + 1, input.ReadCallCount); Assert.AreEqual(expectedCallCount, output.WriteCallCount); }
private static void ValidateCopier(int bufferLength, long? copyLength, long? maxLength, bool inputSync, int inputDelayInMs, int inputFailRequest, bool outputSync, int outputDelayInMs, int outputFailRequest, DateTime? copyTimeout, bool seekable) { byte[] buffer = GetRandomBuffer(bufferLength); // Finds ceiling of division operation int expectedCallCount = (int) (copyLength.HasValue && buffer.Length > copyLength ? (-1L + copyLength + Constants.DefaultBufferSize) / Constants.DefaultBufferSize : (-1L + buffer.Length + Constants.DefaultBufferSize) / Constants.DefaultBufferSize); int totalDelayInMs = (expectedCallCount + 1) * inputDelayInMs + expectedCallCount * outputDelayInMs; DataValidationStream input = new DataValidationStream(buffer, inputSync, inputDelayInMs, inputFailRequest, seekable); DataValidationStream output = new DataValidationStream(buffer, outputSync, outputDelayInMs, outputFailRequest, seekable); RESTCommand<NullType> cmdWithTimeout = new RESTCommand<NullType>(new StorageCredentials(), null) { OperationExpiryTime = copyTimeout }; ExecutionState<NullType> state = new ExecutionState<NullType>(cmdWithTimeout, null, null); StreamDescriptor copyState = new StreamDescriptor(); using (ManualResetEvent waitHandle = new ManualResetEvent(false)) { input.WriteToAsync(output, copyLength, maxLength, false, state, copyState, _ => waitHandle.Set()); Assert.IsTrue(waitHandle.WaitOne(totalDelayInMs + 10 * 1000)); } if (inputFailRequest >= 0) { Assert.AreEqual(input.LastException, state.ExceptionRef); Assert.AreEqual(inputFailRequest, input.ReadCallCount); } if (outputFailRequest >= 0) { Assert.AreEqual(output.LastException, state.ExceptionRef); Assert.AreEqual(outputFailRequest, output.WriteCallCount); } if (state.ExceptionRef != null) { throw state.ExceptionRef; } Assert.AreEqual(copyLength.HasValue ? copyLength : buffer.Length, copyState.Length); Assert.AreEqual(copyLength.HasValue ? expectedCallCount : expectedCallCount + 1, input.ReadCallCount); Assert.AreEqual(expectedCallCount, output.WriteCallCount); }