public async Task BandwidthCheckTimesOutOnSlowCopyByUsingCopyToOptions() { var checkInterval = TimeSpan.FromSeconds(1); var actualBandwidthBytesPerSec = 1024; var actualBandwidth = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec); var bandwidthLimit = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec / 2); // Making sure the actual bandwidth checking options more permissive. var totalBytes = actualBandwidthBytesPerSec * 2; var checkerConfig = new BandwidthChecker.Configuration(checkInterval, bandwidthLimit, maxBandwidthLimit: null, bandwidthLimitMultiplier: null, historicalBandwidthRecordsStored: null); var checker = new BandwidthChecker(checkerConfig); using (var stream = new MemoryStream()) { var bandwidthConfiguration = new BandwidthConfiguration() { Interval = checkInterval, RequiredBytes = actualBandwidthBytesPerSec * 2, }; var options = new CopyOptions(bandwidthConfiguration); var result = await checker.CheckBandwidthAtIntervalAsync( _context, token => CopyRandomToStreamAtSpeed(token, stream, totalBytes, actualBandwidth, options), options, getErrorResult : diagnostics => new CopyFileResult(CopyResultCode.CopyBandwidthTimeoutError, diagnostics)); Assert.Equal(CopyResultCode.CopyBandwidthTimeoutError, result.Code); } }
private static BandwidthChecker.Configuration GetConfiguration() { var checkInterval = TimeSpan.FromSeconds(1); var actualBandwidthBytesPerSec = 1024; var bandwidthLimit = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec / 2); // Lower limit is half actual bandwidth var checkerConfig = new BandwidthChecker.Configuration(checkInterval, bandwidthLimit, maxBandwidthLimit: null, bandwidthLimitMultiplier: null, historicalBandwidthRecordsStored: null); return(checkerConfig); }
public async Task BandwidthCheckTimesOutOnSlowCopy() { var checkInterval = TimeSpan.FromSeconds(1); var actualBandwidthBytesPerSec = 1024; var actualBandwidth = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec); var bandwidthLimit = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec * 2); // Lower limit is twice actual bandwidth var totalBytes = actualBandwidthBytesPerSec * 2; var checkerConfig = new BandwidthChecker.Configuration(checkInterval, bandwidthLimit, maxBandwidthLimit: null, bandwidthLimitMultiplier: null, historicalBandwidthRecordsStored: null); var checker = new BandwidthChecker(checkerConfig); using (var stream = new MemoryStream()) { var result = await checker.CheckBandwidthAtIntervalAsync(_context, token => CopyRandomToStreamAtSpeed(token, stream, totalBytes, actualBandwidth), stream); Assert.Equal(CopyFileResult.ResultCode.CopyBandwidthTimeoutError, result.Code); } }
public async Task BandwidthCheckDoesNotAffectGoodCopies() { var checkInterval = TimeSpan.FromSeconds(1); var actualBandwidthBytesPerSec = 1024; var actualBandwidth = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec); var bandwidthLimit = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec / 2); // Lower limit is half actual bandwidth var totalBytes = actualBandwidthBytesPerSec * 2; var checkerConfig = new BandwidthChecker.Configuration(checkInterval, bandwidthLimit, maxBandwidthLimit: null, bandwidthLimitMultiplier: null, historicalBandwidthRecordsStored: null); var checker = new BandwidthChecker(checkerConfig); using (var stream = new MemoryStream()) { var result = await checker.CheckBandwidthAtIntervalAsync(_context, token => CopyRandomToStreamAtSpeed(token, stream, totalBytes, actualBandwidth), stream); Assert.True(result.Succeeded); } }
public async Task BandwidthCheckDoesNotAffectGoodCopies() { var checkInterval = TimeSpan.FromSeconds(1); var actualBandwidthBytesPerSec = 1024; var actualBandwidth = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec); var bandwidthLimit = MbPerSec(bytesPerSec: actualBandwidthBytesPerSec / 10); // Lower limit significantly to actual bandwidth var totalBytes = actualBandwidthBytesPerSec * 2; var checkerConfig = new BandwidthChecker.Configuration(checkInterval, bandwidthLimit, maxBandwidthLimit: null, bandwidthLimitMultiplier: null, historicalBandwidthRecordsStored: null); var checker = new BandwidthChecker(checkerConfig); using (var stream = new MemoryStream()) { var options = new CopyOptions(bandwidthConfiguration: null); var result = await checker.CheckBandwidthAtIntervalAsync( _context, token => CopyRandomToStreamAtSpeed(token, stream, totalBytes, actualBandwidth, options), options, getErrorResult : diagnostics => new CopyFileResult(CopyResultCode.CopyBandwidthTimeoutError, diagnostics)); result.ShouldBeSuccess(); } }
/// <nodoc /> public BandwidthCheckedCopier(IFileCopier <T> inner, BandwidthChecker.Configuration config, ILogger logger) { _inner = inner; _checker = new BandwidthChecker(config); _logger = logger; }
/// <nodoc /> public BandwidthCheckedCopier(IAbsolutePathRemoteFileCopier inner, BandwidthChecker.Configuration config) { _inner = inner; _checker = new BandwidthChecker(config); }