示例#1
0
        public IntegrationTest()
        {
            TestServer testServer = CreateTestServer();

            var client = testServer.CreateClient();
            //Build REST Client that has the test servers HttpClient
            var address = string.Format("{0}api", testServer.BaseAddress);
            Mock<RestClient> restClientMock = new Mock<RestClient>(address) {CallBase = true};

            restClientMock.Protected().Setup<HttpClient>("GetHttpClient").Returns(client);
            //Build API that has the REST client
            Mock<OjibweApi> apiMock = new Mock<OjibweApi>(testServer.BaseAddress.ToString(), null) {CallBase = true};
            apiMock.Protected().Setup<IRestClient>("GetRestClient").Returns(restClientMock.Object);

            apiMock.Protected().Setup<IWebSocketClient>("GetWebSocketClient").Returns(new TestHostWebSocketClient(testServer.CreateWebSocketClient(), testServer.BaseAddress.ToString()));

            //Pass API to OjibweClient
            _ojibweClient = new OjibweClient(testServer.BaseAddress.ToString(),
                new Log4NetLogger(new FileInfo(Path.Combine("wwwroot", "web.config"))),
                apiMock.Object);
        }
示例#2
0
        public static void RunMultiUserTest(string endpoint)
        {
            int numberOfUsers = 10;
            int numberOfContainers = 10;
            Stream publicPrivateKeyStream;

            var createUsers = Task.Factory.StartNew(() =>
            {
                Parallel.For(0, numberOfUsers, new ParallelOptions() { MaxDegreeOfParallelism = 3 }, (i) =>
                {
                    OjibweClient client = new OjibweClient(endpoint);

                    Random r = new Random(i);
                    var username = string.Format("Benchmark_{0}_{1}", DateTime.Now.Ticks.ToString(), i);
                    var password = DateTime.Now.Ticks.ToString();

                    var sdkUser = client.Register(username, password, out publicPrivateKeyStream);
                    if (sdkUser == null)
                        throw new ApplicationException("Could not register benchmark user.");

                    Console.WriteLine("Created user: {0}", username);

                    var createContainersAndBlobs = Task.Factory.StartNew(() =>
                    {
                        Parallel.For(0, numberOfContainers, new ParallelOptions() { MaxDegreeOfParallelism = 3 },
                            (j) =>
                            {
                                try
                                {
                                    var sdkContainer = sdkUser.Containers.New();
                                    sdkContainer.Name = string.Format("Container_{0}", j);
                                    sdkContainer.Save();

                                    Console.WriteLine("Created Container: {0}", sdkContainer.Name);

                                    var sdkSubContainer = sdkContainer.SubContainers.New();
                                    sdkSubContainer.Name = string.Format("SubContainer_{0}", j);
                                    sdkSubContainer.Save();

                                    Console.WriteLine("Created SubContainer: {0}", sdkSubContainer.Name);

                                    for (int k = 0; k < 10; k++)
                                    {
                                        try
                                        {
                                            byte[] buffer = new byte[(k + 1) * 1024];
                                            r.NextBytes(buffer);

                                            var sdkBlob = sdkContainer.Blobs.New();
                                            sdkBlob.SetData(sdkUser, new MemoryStream(buffer));

                                            Guid hash = new Guid(MD5.Create().ComputeHash(buffer));

                                            sdkBlob.Info.Add("Checksum", hash.ToString());

                                            for (int h = 0; h < 25; h++)
                                            {
                                                sdkBlob.Info.Add(string.Format("Key_{0}", h),
                                                    string.Format("Value_{0}", h));
                                            }

                                            sdkBlob.Save();
                                            Console.WriteLine("Stored blob with checksum: {0}, in containers: {1}", hash,
                                                sdkContainer.Name);
                                        }
                                        catch (Exception ex)
                                        {
                                            Console.WriteLine(ex);
                                        }

                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                }
                            });
                    });

                    Task.WaitAll(createContainersAndBlobs);

                    var readContainersAndBlobs = Task.Factory.StartNew(() =>
                    {
                        Parallel.ForEach(sdkUser.Containers.Items, new ParallelOptions() { MaxDegreeOfParallelism = 1 },
                        sdkContainer =>
                        {
                            try
                            {
                                Console.WriteLine("Reading container {0}", sdkContainer.Name);

                                foreach (SdkBlob sdkBlob in sdkContainer.Blobs.Items)
                                {
                                    try
                                    {
                                        Console.WriteLine("\tReading blob {0}", sdkBlob.Id);

                                        foreach (KeyValuePair<string, string> keyValuePair in sdkBlob.Info)
                                        {
                                            Console.WriteLine("\tInfo: {0}:{1}", keyValuePair.Key, keyValuePair.Value);
                                        }

                                        using (var stream = sdkBlob.GetData(sdkUser))
                                        {
                                            var bytes = ReadFully(stream);
                                            Guid hash = new Guid(MD5.Create().ComputeHash(bytes));

                                            string checkSum = null;
                                            if (!sdkBlob.Info.TryGetValue("Checksum", out checkSum))
                                                Console.WriteLine("BlobId: {0} - Could not find Checksum info.", sdkBlob.Id);

                                            if (string.IsNullOrWhiteSpace(checkSum))
                                                Console.WriteLine("BlobId: {0} - Found checksum info, but checkusm is null.", sdkBlob.Id);

                                            if (checkSum != null)
                                            {
                                                var actual = Guid.Parse(checkSum);
                                                Console.WriteLine(actual == hash ? "Checksum Valid" : "Checksum did not match");
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine(ex);
                                    }

                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        });
                    });

                    Task.WaitAll(readContainersAndBlobs);
                });

            });

            Task.WaitAll(createUsers);
        }
示例#3
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            if (args.Length < 1)
                throw new ApplicationException("Please specify Ojibwe endpoint.");

            string address = args[0];

            OjibweClient client = new OjibweClient(address);

            string username = string.Format("StressTest{0}", DateTime.Now.Ticks.ToString());
            Stream privateKey = null;
            var currentUser = client.Register(username, "Password01", out privateKey);

            for (int i = 0; i < 10; i++)
            {
                Container container = new Container();
                container.Name = string.Format("Container_{0}", i);
                currentUser.Containers.Add(container);
            }

            Random random = new Random();

            foreach (var container in currentUser.Containers.Items)
            {
                byte[] randomBytes = new byte[64];
                for (int i = 0; i < 100; i++)
                {
                    try
                    {
                        random.NextBytes(randomBytes);

                        Guid checksum = Guid.Empty;
                        lock (md5)
                            checksum = new Guid(md5.ComputeHash(randomBytes));
                        MemoryStream ms = new MemoryStream(randomBytes);

                        var sdkBlob = container.StoreBlob(ms, currentUser.PublicKey,
                            new KeyValuePair<string, string>("DateTime.Ticks", DateTime.Now.Ticks.ToString()),
                            new KeyValuePair<string, string>("CheckSum", checksum.ToString()));
                        Console.WriteLine("Stored BlobId: {0}", sdkBlob.Id);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to store blob.");
                    }
                }
            }
            Parallel.ForEach(currentUser.Containers.Items, new ParallelOptions() { MaxDegreeOfParallelism = 8 },
                (container) =>
                {
                    foreach (var blob in container.Blobs.Items)
                    {
                        Console.WriteLine("BlobID: {0}", blob.Id);
                        string checkSum = null;
                        if (!blob.Info.TryGetValue("CheckSum", out checkSum))
                        {
                            Console.WriteLine("Could not find checksum.");
                            continue;
                        }

                        Guid g = Guid.Parse(checkSum);
                        var bytes = StreamUtility.GetBytes(currentUser.DecryptBlob(blob, privateKey));

                        if(!VerifyCheckSum(g, bytes))
                            Console.WriteLine("CheckSums did not match for BlobId: {0}", blob.Id);
                    }
                });
        }