コード例 #1
0
        static async Task RunAsync()
        {
            const string Access = "YourAccessTokenValueHere";
            const string Admin  = "YourAdminTokenValueHere";

            var zone = new DropZoneConfig
            {
                BaseUrl        = "http://localhost:5000",
                ZoneName       = "Update",
                Password       = string.Empty,
                Salt           = string.Empty,
                UseEncryption  = false,
                AccessToken    = Access,
                AdminToken     = Admin,
                TimeoutSeconds = 10
            };

            var restApiUpdateMaster = new RestApiCalls(zone);

            try
            {
                Console.WriteLine("CheckHeartbeat()...");
                Result result = await restApiUpdateMaster.CheckHeartbeat();

                DisplayResult(result, 100);
                if (result.HandleAs == Result.State.InvalidAuthentication)
                {
                    Console.WriteLine("Invalid auth token, testing halted... ");
                    return;
                }

                Console.WriteLine("Reset()...");
                result = await restApiUpdateMaster.Reset();

                DisplayResult(result, 100);
                if (result.HandleAs == Result.State.InvalidAuthentication)
                {
                    Console.WriteLine("Invalid admin token, testing halted... ");
                    return;
                }

                Console.WriteLine("SetMetrics()... fails.");
                result = await restApiUpdateMaster.SetMetrics(new Common.Dto.DropZoneMetrics
                {
                    MaxPayloadCount    = 1,
                    MaxPayloadSize     = 1,
                    MaxReferencesCount = 2,
                    MaxReferenceSize   = 2
                });

                DisplayResult(result, -1);

                Console.WriteLine("ListReferences()... ");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... ");
                result = await restApiUpdateMaster.GetReference("Test-Ref01");

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... ");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("SetReference()... ");
                result = await restApiUpdateMaster.SetReference("Test-Ref01", "test ref 1");

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... ");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... ");
                result = await restApiUpdateMaster.GetReference("Test-Ref01");

                DisplayResult(result, 1000);

                Console.WriteLine("SetReference()... Perishable");
                result = await restApiUpdateMaster.SetReference("Test-Ref02-Perish-5-Sec", "this will go way", DateTime.Now.AddSeconds(5));

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... shows static and perishable");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... Perishable ... < 1 sec (finds it)");
                result = await restApiUpdateMaster.GetReference("Test-Ref02-Perish-5-Sec");

                DisplayResult(result, 1000);

                Console.WriteLine("Wait 5 seconds for reference to expire...");
                Thread.Sleep(5000);

                Console.WriteLine("ListReferences()... shows static only... perishable has expired");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... Perishable ... > 5 sec (perished)");
                result = await restApiUpdateMaster.GetReference("RefTimed-Good");

                DisplayResult(result, -1);

                Console.WriteLine("SetReference()");
                result = await restApiUpdateMaster.SetReference("Test-Ref03", "this will go way");

                Console.WriteLine("GetReference()");
                result = await restApiUpdateMaster.GetReference("Test-Ref03");

                Console.WriteLine("DropReference()");
                result = await restApiUpdateMaster.DropReference("Test-Ref03");

                Console.WriteLine("GetReference()");
                result = await restApiUpdateMaster.GetReference("Test-Ref03");

                DisplayResult(result, -1);

                Console.WriteLine("SetReference()... BIG...");
                var bigData = new string('X', 524288);
                Console.WriteLine($"{bigData.Length}");
                result = await restApiUpdateMaster.SetReference("BIG", bigData);

                DisplayResult(result, 1000);

                Console.WriteLine("GetReference()... BIG...");
                result = await restApiUpdateMaster.GetReference("BIG");

                Console.WriteLine($"{result.Message.Length}");
                result.Message = string.Empty;
                DisplayResult(result, 1000);

                Console.WriteLine("SetReference()... HUGE... rejected due to size");
                var hugeData = new string('X', 41000000);
                Console.WriteLine($"{hugeData.Length}");
                result = await restApiUpdateMaster.SetReference("HUGE", hugeData);

                DisplayResult(result, 1000);

                Console.WriteLine("GetReference()... HUGE...");
                result = await restApiUpdateMaster.GetReference("HUGE");

                Console.WriteLine($"{result.Message.Length}");
                result.Message = string.Empty;
                DisplayResult(result, -1);

                Console.WriteLine("GetStatistics()... ");
                result = await restApiUpdateMaster.GetStatistics();

                DisplayResult(result, -1);
                Console.WriteLine("GetSecurityInfo()... ");
                result = await restApiUpdateMaster.GetSecurity();

                DisplayResult(result, -1);

                // Payloads and recipients

                // Test a payload with and without a specific recipient

                Console.WriteLine("*** Drop off to global (1) and to a specific recipient (1)");
                Console.WriteLine($"Add \"Global payload\" for global queue in the zone ... ");
                result = await restApiUpdateMaster.DropOff("Global payload");

                DisplayResult(result, 0);

                var recipient = "Tim";
                Console.WriteLine($"Add \"Tim's payload\" for {recipient} queue in the zone ... ");
                result = await restApiUpdateMaster.DropOff("Tim's payload", recipient);

                DisplayResult(result, 0);

                Console.WriteLine($"Retrieve payload for recipient {recipient} ...");
                result = await restApiUpdateMaster.Pickup(recipient);

                DisplayResult(result, 0);

                Console.WriteLine($"Retrieve payload for recipient {recipient} ... should have nothing");
                result = await restApiUpdateMaster.Pickup(recipient);

                DisplayResult(result, 0);

                Console.WriteLine($"Retrieve payload for global use ...");
                result = await restApiUpdateMaster.Pickup();

                DisplayResult(result, 0);

                Console.WriteLine($"Retrieve payload for global use ... should have nothing");
                result = await restApiUpdateMaster.Pickup();

                DisplayResult(result, -1);

                // Other payloads tests.

                string[] set = new string[] { "Tallahunda", "Kookamunga", "Whatever" };

                Console.WriteLine("*** Drop off some data .. which expires ***");
                for (int index = 0; index < 5; index++)
                {
                    Console.WriteLine($"Add {index}: {set[index % 3]}... ");
                    result = await restApiUpdateMaster.DropOff(set[index % 3] + $"{index}", DateTime.Now.AddSeconds(3 + index));

                    DisplayResult(result, 0);
                }

                Console.WriteLine("Wait 5 for reference to expire...");
                Thread.Sleep(5000);

                Console.WriteLine("*** Pickup some data .. some of which has expired ***");
                for (int index = 0; index < 5; index++)
                {
                    Console.WriteLine($"Retrieve {index} from {set[index % 3]}: ");
                    result = await restApiUpdateMaster.Pickup();

                    DisplayResult(result, 0);
                }

                Console.WriteLine("*** Clear ***");
                result = await restApiUpdateMaster.Clear();

                DisplayResult(result, -1);

                Console.WriteLine("*** Drop off some data.. places 501 items when 500 is the max ***");
                //for (int index = 0; index < 501; index++)
                for (int index = 0; index < 101; index++)
                {
                    Console.WriteLine($"Add {index}: {set[index % 3]}... ");
                    result = await restApiUpdateMaster.DropOff(set[index % 3]);

                    DisplayResult(result, index < 5 ? 1000 : 0);
                }
                Console.WriteLine("GetStatistics()...");
                result = await restApiUpdateMaster.GetStatistics();

                DisplayResult(result, -1);

                Console.WriteLine("*** Pickup some data ***");
                //for (int index = 0; index < 502; index++)
                for (int index = 0; index < 102; index++)
                {
                    Console.WriteLine($"Retrieve {index} from {set[index % 3]}: ");
                    result = await restApiUpdateMaster.Pickup();

                    DisplayResult(result, index == 2 ? -1 : (index < 5 ? 1000 : 0));
                }

                Console.WriteLine("*** List references ***");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("Overload references...");
                for (int index = 0; index < 48; index++)
                {
                    Console.WriteLine($"SetReference(Ref-{BOG.SwissArmyKnife.Formatting.RJLZ(index, 2)}... ");
                    result = await restApiUpdateMaster.SetReference($"Ref-{BOG.SwissArmyKnife.Formatting.RJLZ(index, 2)}", $"test ref {index}");

                    DisplayResult(result, 0);
                }

                Console.WriteLine("*** List references after overload ***");
                result = await restApiUpdateMaster.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetStatistics()... ");
                result = await restApiUpdateMaster.GetStatistics();

                DisplayResult(result, -1);

                Console.WriteLine("*** Reset ***");
                result = await restApiUpdateMaster.Reset();

                DisplayResult(result, 2000);

                Console.WriteLine("*** Shutdown ***");
                result = await restApiUpdateMaster.Shutdown();

                DisplayResult(result, 2000);

                Console.WriteLine("*** Shutdown (with no answer) ***");
                result = await restApiUpdateMaster.Shutdown();

                DisplayResult(result, 2000);
            }
            catch (Exception err)
            {
                Console.WriteLine($"Untrapped: {err.Message}");
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rambotech/BOG.DropZone
        static async Task UnitTestAsync()
        {
            Console.WriteLine("Setup()...");
            const string Access = "YourAccessTokenValueHere";
            const string Admin  = "YourAdminTokenValueHere";

            var zone = new DropZoneConfig
            {
                BaseUrl        = "http://*****:*****@"C:\Users\johnm\research\RR-Dynamic-20201216-C.result.json";
                string bigFishContent = null;
                using (var t = new StreamReader(bigFish))
                {
                    bigFishContent = t.ReadToEnd();
                    result         = await restApiUpdateMaster.SetBlob("TestItem02", bigFishContent);
                }
                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                Console.Write("Clear DropZone ...: ");
                result = await restApiUpdateMaster.Clear();

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                Console.WriteLine("Read blob list ...: ");
                result = await restApiUpdateMaster.ListBlobs();

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write($"  Blob list has previous items ...: ");
                    var blobCount = Serializer <System.Collections.Generic.List <System.String> > .FromJson(result.Content).Count;

                    testPassed = (blobCount == 2);
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: 2, got: {blobCount}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                // Read the blob item TestItem01: test for proper content.
                Console.Write("Read Blob TestItem01 ...: ");
                result = await restApiUpdateMaster.GetBlob("TestItem01");

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write("  Valid Blob Content TestItem01 ...: ");
                    testPassed |= string.Compare(result.Content, TestItem01Value, false) == 0;
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: (empty string), got: {result.Content}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;

                // Read the blob item TestItem01: test for proper content.
                Console.Write("Read Blob TestItem02 ...: ");
                result = await restApiUpdateMaster.GetBlob("TestItem02");

                testPassed = result.HandleAs == Result.State.OK;
                Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: OK, got: {result.HandleAs}");
                if (testPassed)
                {
                    Console.Write("  Valid Blob Content TestItem02 ...: ");
                    testPassed |= string.Compare(result.Content, bigFishContent, false) == 0;
                    Console.WriteLine(testPassed ? "pass" : $"FAIL, expected: (empty string), got: {result.Content}");
                }
                if (!testPassed)
                {
                    UnexpectedResult();
                }
                testPassed = true;
            }
            catch (Exception err)
            {
                Console.WriteLine($"Untrapped: {err.Message}");
            }

            Console.WriteLine("---------------------------");
            Console.WriteLine("### TESTING ENDS ###");
            Console.WriteLine("---------------------------");
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("Press ENTER to finish");
            Console.ReadLine();
#endif
        }
コード例 #3
0
        static async Task RunAsync()
        {
            int testIndex = 0;

            // Add your own test location to this array, and set the testIndex value to run against that location.
            DropZoneConfig[] dropZoneConfigs = new DropZoneConfig[]
            {
                new DropZoneConfig
                {
                    BaseUrl        = "http://localhost:5000",
                    ZoneName       = "CityData",
                    Password       = "******",
                    Salt           = "YourSalt",
                    UseEncryption  = false,
                    AccessToken    = "YourAccessValueHere",
                    AdminToken     = "YourAdminValueHere ",
                    TimeoutSeconds = 10
                }
            };
            RestApiCalls restApi = new RestApiCalls(dropZoneConfigs[testIndex]);

            try
            {
                Console.WriteLine("CheckHeartbeat()...");
                Result result = await restApi.CheckHeartbeat();

                DisplayResult(result, 1000);
                if (result.HandleAs == Result.State.InvalidAuthentication)
                {
                    Console.WriteLine("Invalid auth token, testing halted... ");
                    return;
                }

                Console.WriteLine("Reset()... ");
                result = await restApi.Reset();

                DisplayResult(result, 100);

                Console.WriteLine("ListReferences()... ");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... ");
                result = await restApi.GetReference("Test-Ref01");

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... ");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("SetReference()... ");
                result = await restApi.SetReference("Test-Ref01", "test ref 1");

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... ");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... ");
                result = await restApi.GetReference("Test-Ref01");

                DisplayResult(result, 1000);

                Console.WriteLine("SetReference()... Perishable");
                result = await restApi.SetReference("Test-Ref02-Perish-5-Sec", "this will go way", DateTime.Now.AddSeconds(5));

                DisplayResult(result, 1000);

                Console.WriteLine("ListReferences()... shows static and perishable");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... Perishable ... < 1 sec (finds it)");
                result = await restApi.GetReference("Test-Ref02-Perish-5-Sec");

                DisplayResult(result, 1000);

                Console.WriteLine("Wait 5 seconds for reference to expire...");
                Thread.Sleep(5000);

                Console.WriteLine("ListReferences()... shows static only... perishable has expired");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetReference()... Perishable ... > 5 sec (perished)");
                result = await restApi.GetReference("RefTimed-Good");

                DisplayResult(result, -1);

                Console.WriteLine("SetReference()... BIG...");
                var bigData = new string('X', 524288);
                Console.WriteLine($"{bigData.Length}");
                result = await restApi.SetReference("BIG", bigData);

                DisplayResult(result, 1000);

                Console.WriteLine("GetReference()... BIG...");
                result = await restApi.GetReference("BIG");

                Console.WriteLine($"{result.Message.Length}");
                result.Message = string.Empty;
                DisplayResult(result, 1000);

                Console.WriteLine("SetReference()... HUGE... rejected due to size");
                var hugeData = new string('X', 41000000);
                Console.WriteLine($"{hugeData.Length}");
                result = await restApi.SetReference("HUGE", hugeData);

                DisplayResult(result, 1000);

                Console.WriteLine("GetReference()... HUGE...");
                result = await restApi.GetReference("HUGE");

                Console.WriteLine($"{result.Message.Length}");
                result.Message = string.Empty;
                DisplayResult(result, -1);

                Console.WriteLine("GetStatistics()... ");
                result = await restApi.GetStatistics();

                DisplayResult(result, -1);
                Console.WriteLine("GetSecurityInfo()... ");
                result = await restApi.GetSecurity();

                DisplayResult(result, -1);

                string[] set = new string[] { "Tallahunda", "Kookamunga", "Whatever" };

                Console.WriteLine("*** Drop off some data .. which expires ***");
                for (int index = 0; index < 5; index++)
                {
                    Console.WriteLine($"Add {index}: {set[index % 3]}... ");
                    result = await restApi.DropOff(set[index % 3] + $"{index}", DateTime.Now.AddSeconds(3 + index));

                    DisplayResult(result, 0);
                }

                Console.WriteLine("Wait 5 for reference to expire...");
                Thread.Sleep(5000);

                Console.WriteLine("*** Pickup some data .. some of which has expired ***");
                for (int index = 0; index < 5; index++)
                {
                    Console.WriteLine($"Retrieve {index} from {dropZoneConfigs[testIndex].ZoneName}: ");
                    result = await restApi.Pickup();

                    DisplayResult(result, 0);
                }

                Console.WriteLine("*** Clear ***");
                result = await restApi.Clear();

                DisplayResult(result, -1);

                Console.WriteLine("*** Drop off some data.. places 501 items when 500 is the max ***");
                for (int index = 0; index < 501; index++)
                {
                    Console.WriteLine($"Add {index}: {set[index % 3]}... ");
                    result = await restApi.DropOff(set[index % 3]);

                    DisplayResult(result, index < 5 ? 1000 : 0);
                }
                Console.WriteLine("GetStatistics()...");
                result = await restApi.GetStatistics();

                DisplayResult(result, -1);

                Console.WriteLine("*** Pickup some data ***");
                for (int index = 0; index < 502; index++)
                {
                    Console.WriteLine($"Retrieve {index} from {dropZoneConfigs[testIndex].ZoneName}: ");
                    result = await restApi.Pickup();

                    DisplayResult(result, index == 2 ? -1 : (index < 5 ? 1000 : 0));
                }

                Console.WriteLine("*** List references ***");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("Overload references...");
                for (int index = 0; index < 48; index++)
                {
                    Console.WriteLine($"SetReference(Ref-{BOG.SwissArmyKnife.Formatting.RJLZ(index, 2)}... ");
                    result = await restApi.SetReference($"Ref-{BOG.SwissArmyKnife.Formatting.RJLZ(index, 2)}", $"test ref {index}");

                    DisplayResult(result, 0);
                }

                Console.WriteLine("*** List references after overload ***");
                result = await restApi.ListReferences();

                DisplayResult(result, -1);

                Console.WriteLine("GetStatistics()... ");
                result = await restApi.GetStatistics();

                DisplayResult(result, -1);

                Console.WriteLine("*** Reset ***");
                result = await restApi.Reset();

                DisplayResult(result, 2000);

                Console.WriteLine("*** Shutdown ***");
                result = await restApi.Shutdown();

                DisplayResult(result, 2000);

                Console.WriteLine("*** Shutdown (with no answer) ***");
                result = await restApi.Shutdown();

                DisplayResult(result, 2000);
            }
            catch (Exception err)
            {
                Console.WriteLine($"Untrapped: {err.Message.ToString()}");
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }