public async Task ShouldDisposeTransports()
        {
            var @base = new Base();

            @base["test"] = "the best";

            var myLocalTransport = new SQLiteTransport();
            var id = await Operations.Send(@base, new List <ITransport>() { myLocalTransport }, false, disposeTransports : true);

            // Send
            try
            {
                await Operations.Send(@base, new List <ITransport>() { myLocalTransport }, false, disposeTransports : true);

                Assert.Fail("Send operation did not dispose of transport.");
            }
            catch (Exception)
            {
                // Pass
            }

            myLocalTransport = myLocalTransport.Clone() as SQLiteTransport;
            var obj = await Operations.Receive(id, null, myLocalTransport, disposeTransports : true);

            try
            {
                await Operations.Receive(id, null, myLocalTransport);

                Assert.Fail("Receive operation did not dispose of transport.");
            }
            catch
            {
                // Pass
            }
        }
예제 #2
0
        /// <summary>
        /// Some stress tests for the sqlite transport. Perhaps useful later.
        /// </summary>
        /// <returns></returns>
        public static async Task SqliteStressTest()
        {
            int numObjects = 100_000;
            var transport  = new SQLiteTransport();
            var rand       = new Random();
            var stopWatch  = new Stopwatch();

            Console.WriteLine($"-------------------------------------------------\n");
            Console.WriteLine($"Starting to save {numObjects} of objects");

            stopWatch.Start();

            for (int i = 0; i < numObjects; i++)
            {
                //var hash = Speckle.Core.Models.Utilities.hashString($"hash-{i}-{rand.NextDouble()}");
                transport.SaveObject($"hash-{i}-{rand.NextDouble()}", $"content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}content-longer-maye-it's-ok-{i}");
            }

            // waits for the buffer to be empty.
            await transport.WriteComplete();

            var stopWatchStep = stopWatch.ElapsedMilliseconds;
            var objsPerSecond = (double)numObjects / (stopWatchStep / 1000);

            Console.WriteLine($"-------------------------------------------------");
            Console.WriteLine($"BufferedWriteTest: Wrote {numObjects} in {stopWatchStep} ms -> {objsPerSecond} objects per second");
            Console.WriteLine($"-------------------------------------------------\n");
        }
        public async Task ShouldNotDisposeTransports()
        {
            var @base = new Base();

            @base["test"] = "the best";

            var myLocalTransport = new SQLiteTransport();
            var id = await Operations.Send(@base, new List <ITransport>() { myLocalTransport }, false);

            await Operations.Send(@base, new List <ITransport>() { myLocalTransport }, false);

            var obj = await Operations.Receive(id, null, myLocalTransport);

            await Operations.Receive(id, null, myLocalTransport);
        }