Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
V0.46 Connector Enhancements - request Throttling
Browse files Browse the repository at this point in the history
Connector supports throttling to a target number of requests per second.
Delays are added in APIExecuteVerb() to enforce the maximum.  Requests
per second are tracked by endpoint across cloned connectors.
  • Loading branch information
stanyork committed Feb 2, 2015
1 parent 572ba1d commit 8f464ce
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 38 deletions.
45 changes: 45 additions & 0 deletions Cloud Element Test Form/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 31 additions & 26 deletions Cloud Element Test Form/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private async Task RunUnitTest()
TestStatusMsg("Testing with " + toolStripTxtConnectionNow.Text);
string basepath = txtFolderPath.Text;
SerializeGetFileMetadataRequests = chkSerializeGetFileInfoReq.Checked;
APIConnector.EndpointMaxRequestsPerSecond = (int)spnRequestsPerSecond.Value;

if (basepath.EndsWith("/")) { basepath.TrimEnd(new char[] { '/' }); }
string tfoldername = basepath + "/Cloud Elements API Test Folder";
Expand Down Expand Up @@ -261,12 +262,12 @@ private async Task RunUnitTest()

AsyncUploadTest = new Task<Task<string>>(UploadTestAction);
AsyncUploadTest.Start();
AwaitableTestTask = AsyncUploadTest.ConfigureAwait(false);
FinalAwaitableTestTask = await AwaitableTestTask;
info = await FinalAwaitableTestTask;
AwaitableTestTask = AsyncUploadTest.ConfigureAwait(false);
FinalAwaitableTestTask = await AwaitableTestTask;
info = await FinalAwaitableTestTask;
TestStatusMsg(info);
AsyncUploadPassed = true;

NumberOfFilesAlreadyUploaded = 8;
}
catch (Exception eu)
Expand All @@ -278,12 +279,12 @@ private async Task RunUnitTest()
if (AsyncUploadPassed)
{
//SEVENTH TEST: repeat Async Uploads
UploadTestAction = new System.Func<Task<string>>(TestMultiFileAsyncUploads);
AsyncUploadTest = new Task<Task<string>>(UploadTestAction) ;
TestStatusMsg("Test: Repeat Multiple ASYNC uploads, without waiting...");
AsyncUploadTest.Start();
AwaitableTestTask = AsyncUploadTest.ConfigureAwait(false);
UploadTestAction = new System.Func<Task<string>>(TestMultiFileAsyncUploads);
AsyncUploadTest = new Task<Task<string>>(UploadTestAction);
TestStatusMsg("Test: Repeat Multiple ASYNC uploads, without waiting...");
AsyncUploadTest.Start();
AwaitableTestTask = AsyncUploadTest.ConfigureAwait(false);

}

//EIGHTH TEST: Download File
Expand Down Expand Up @@ -339,15 +340,15 @@ private async Task RunUnitTest()
System.Runtime.CompilerServices.ConfiguredTaskAwaitable<Task<string>> AwaitableMetaInfoTask;
try
{

// we need to run away from the UI
TestMetaInfoAction = new System.Func<Task<string>>(TestAsyncGetFileMeta);

AsyncMetaInfoTest = new Task<Task<string>>(TestMetaInfoAction);
AsyncMetaInfoTest.Start();
AwaitableMetaInfoTask = AsyncMetaInfoTest.ConfigureAwait(false);
FinalAwaitableMetaInfoTask = await AwaitableMetaInfoTask;


}
catch (Exception eu)
Expand Down Expand Up @@ -379,19 +380,19 @@ private async Task CleanupUnitTest()
TestStatusMsg("Cleaning up test...");
string basepath = txtFolderPath.Text;
if (basepath.EndsWith("/")) { basepath.TrimEnd(new char[] { '/' }); }
string tfoldername = basepath + "/Cloud Elements API Test Folder";
string tfoldername = basepath + "/Cloud Elements API Test Folder";

//check for file on disk
string fn = System.IO.Path.Combine(WorkPath, "SFCE_test_file_1.txt");
if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(fn)))
{
if (System.IO.File.Exists(fn))
{
System.IO.File.Delete(fn);
TestStatusMsg("Downloaded test file deleted");
}
if (System.IO.File.Exists(fn))
{
System.IO.File.Delete(fn);
TestStatusMsg("Downloaded test file deleted");
}
}


//check for folder
try
Expand Down Expand Up @@ -440,15 +441,15 @@ public static string GenerateRandomContent(int bitLen)


int DownloadTestExpectedHash;
int NumberOfFilesAlreadyUploaded=0;
int NumberOfFilesAlreadyUploaded = 0;
bool SerializeGetFileMetadataRequests = true;
string AsyncBasePath;

async Task<string> TestMultiFileAsyncUploads()
{
string tfoldername = AsyncBasePath; // set at start of tests
System.Collections.Generic.Queue<Task<Cloud_Elements_API.CloudFile>> UploadTasks = new System.Collections.Generic.Queue<Task<Cloud_Elements_API.CloudFile>>();
System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector> ConnectorsUsed = new System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector>() ;
System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector> ConnectorsUsed = new System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector>();


DateTime Started = DateTime.Now;
Expand Down Expand Up @@ -476,7 +477,7 @@ async Task<string> TestMultiFileAsyncUploads()

UploadTasks.Enqueue(AnUpload);
uploadCount += 1;

}

int rewaitCnt = 0;
Expand Down Expand Up @@ -531,7 +532,7 @@ async Task<string> TestAsyncGetFileMeta()
{
string tfoldername = AsyncBasePath; // as set at start of tests
System.Collections.Generic.Queue<Task<Cloud_Elements_API.CloudFile>> MetaTasks = new System.Collections.Generic.Queue<Task<Cloud_Elements_API.CloudFile>>();
System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector> ConnectorsUsed = new System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector>() ;
System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector> ConnectorsUsed = new System.Collections.Generic.List<Cloud_Elements_API.CloudElementsConnector>();
DateTime Started = DateTime.Now;
int MetaCount = 0;
for (int rr = 1; rr <= 4; rr++)
Expand Down Expand Up @@ -560,12 +561,16 @@ async Task<string> TestAsyncGetFileMeta()
try
{
Cloud_Elements_API.CloudFile Result = await AnUpload;
Summary.AppendFormat("\t{5}: Task {2} File Info for {0}, id={1}, ok={3} \r\n", Result.name, Result.id, AnUpload.Id, !AnUpload.IsFaulted,
0, Cloud_Elements_API.Tools.TraceTimeNow());
if (Result != null)
Summary.AppendFormat("\t{5}: Task {2} File Info for {0}, id={1}, ok={3} \r\n", Result.name, Result.id, AnUpload.Id, !AnUpload.IsFaulted,
0, Cloud_Elements_API.Tools.TraceTimeNow());
else Summary.AppendFormat("\t{5}: Task {2} did not obtain file Info for {0}, id={1}, ok={3} \r\n", "", "", AnUpload.Id, !AnUpload.IsFaulted,
0, Cloud_Elements_API.Tools.TraceTimeNow());

}
catch (Exception ex)
{
Summary.AppendFormat("\t{5}: Task {2} File Info Exception {0}, ok={3} \r\n", ex.Message , 0, AnUpload.Id, !AnUpload.IsFaulted,
Summary.AppendFormat("\t{5}: Task {2} File Info Exception {0}, ok={3} \r\n", ex.Message, 0, AnUpload.Id, !AnUpload.IsFaulted,
0, Cloud_Elements_API.Tools.TraceTimeNow());

}
Expand Down
Loading

0 comments on commit 8f464ce

Please sign in to comment.