Exemplo n.º 1
0
        internal ProtocolHeadFixture GetFixture()
        {
            ProtocolHeadFixture fixture = new ProtocolHeadFixture();

            this.fixtures.Add(fixture);
            return(fixture);
        }
Exemplo n.º 2
0
 public StoreLimitsTestBase(bool usePersistentStorage)
 {
     ConfigHelper.TestConfig["UsePersistentStorage"] = usePersistentStorage.ToString();
     ConfigHelper.TestConfig["MaxStorageBytes"]      = MaxStorageSize.ToString();
     ConfigHelper.TestConfig["TimeToLiveSecs"]       = "0";
     ConfigHelper.TestConfig["Routes"] = JsonConvert.SerializeObject(Routes);
     this.protocolHeadFixture          = EdgeHubFixtureCollection.GetFixture();
 }
Exemplo n.º 3
0
 public EdgeHubTestFixture()
 {
     if (protocolHeadFixtureInstance == null)
     {
         lock (FixtureLock)
         {
             if (protocolHeadFixtureInstance == null)
             {
                 protocolHeadFixtureInstance = EdgeHubFixtureCollection.GetFixture();
             }
         }
     }
 }
Exemplo n.º 4
0
        public EdgeHubTest(EdgeHubFixture edgeHubFixture)
        {
            this.edgeHubFixture = edgeHubFixture;

            if (protocolHeadFixtureInstance == null)
            {
                lock (FixtureLock)
                {
                    if (protocolHeadFixtureInstance == null)
                    {
                        protocolHeadFixtureInstance = this.edgeHubFixture.GetFixture();
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal static ProtocolHeadFixture GetFixture()
        {
            lock (UpdateLock)
            {
                // Before creating a new fixture, we need to ensure that other ProtocolHeadFixture
                // instances are closed. This is because a ProtocolHeadFixture encapsulates a
                // socket connection over an address and only one usage of this address is allowed
                // at a time.
                foreach (ProtocolHeadFixture fixture in Fixtures)
                {
                    if (!fixture.IsClosed)
                    {
                        fixture.CloseAsync().Wait();
                    }
                }

                ProtocolHeadFixture newFixture = new ProtocolHeadFixture();
                Fixtures.Add(newFixture);
                return(newFixture);
            }
        }
Exemplo n.º 6
0
 public SslProtocolsTest()
 {
     this.protocolHead = EdgeHubFixtureCollection.GetFixture(SslProtocols.Tls12);
 }
Exemplo n.º 7
0
        async Task BackupAndRestoreMessageDeliveryTestBase(
            ITransportSettings[] transportSettings,
            int beforeBackupMessageCount,
            int afterBackupMessageCount,
            int expectedMessageCountAfterRestore,
            Action postBackupModifier)
        {
            ProtocolHeadFixture protocolHeadFixture = EdgeHubFixtureCollection.GetFixture();
            TestModule          sender   = null;
            TestModule          receiver = null;

            string edgeDeviceConnectionString = await SecretsHelper.GetSecretFromConfigKey("edgeCapableDeviceConnStrKey");

            IotHubConnectionStringBuilder connectionStringBuilder = IotHubConnectionStringBuilder.Create(edgeDeviceConnectionString);
            RegistryManager      rm = RegistryManager.CreateFromConnectionString(edgeDeviceConnectionString);
            Func <int, TimeSpan> waitTimeComputer = (numberOfMessages) => TimeSpan.FromMinutes(Math.Ceiling(numberOfMessages / 2000d) + 2);

            try
            {
                sender = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "sender1", transportSettings);

                receiver = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "receiver1", transportSettings);

                Console.WriteLine($"Sending {beforeBackupMessageCount} messages.");

                // Send 10 messages before a receiver is registered.
                Task <int> task1             = sender.SendMessagesByCountAsync("output1", 0, beforeBackupMessageCount, waitTimeComputer(beforeBackupMessageCount));
                int        sentMessagesCount = await task1;
                Assert.Equal(beforeBackupMessageCount, sentMessagesCount);

                TimeSpan waitTime = TimeSpan.FromMinutes(2);
                Console.WriteLine($"Waiting {waitTime.TotalSeconds} seconds before validating receipt of messages.");

                // Wait for a while and then close the test fixture which will in turn close the protocol heads and the in-memory DB store thus creating a backup.
                await Task.Delay(TimeSpan.FromMinutes(2));

                await protocolHeadFixture.CloseAsync();

                Console.WriteLine("Protocol heads closed.");

                postBackupModifier();

                // Get new fixture to re-initialize the edge hub container.
                protocolHeadFixture = EdgeHubFixtureCollection.GetFixture();

                // Reconnect clients due to C# SDK bug where it illegally attempts to send through closed amqp link
                sender = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "sender1", transportSettings);

                receiver = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "receiver1", transportSettings);

                // Register the message handler now.
                await receiver.SetupReceiveMessageHandler();

                Console.WriteLine($"Sending {afterBackupMessageCount} messages.");

                // Send more messages after the receiver is registered.
                Task <int> task2 = sender.SendMessagesByCountAsync("output1", beforeBackupMessageCount, afterBackupMessageCount, TimeSpan.FromMinutes(2));
                sentMessagesCount = await task2;
                Assert.Equal(afterBackupMessageCount, sentMessagesCount);

                waitTime = waitTimeComputer(expectedMessageCountAfterRestore);
                Console.WriteLine($"Waiting {waitTime.TotalSeconds} seconds before validating receipt of messages.");

                // Validate that all the messages were received (both sent earlier and the new messages).
                await Task.Delay(waitTime);

                ISet <int> receivedMessages = receiver.GetReceivedMessageIndices();

                Assert.Equal(expectedMessageCountAfterRestore, receivedMessages.Count);
            }
            finally
            {
                if (rm != null)
                {
                    await rm.CloseAsync();

                    rm.Dispose();
                }

                if (sender != null)
                {
                    await sender.Disconnect();

                    sender.Dispose();
                }

                if (receiver != null)
                {
                    await receiver.Disconnect();

                    receiver.Dispose();
                }

                await protocolHeadFixture.CloseAsync();
            }

            // wait for the connection to be closed on the Edge side
            await Task.Delay(TimeSpan.FromSeconds(10));
        }