コード例 #1
0
        public async Task GatewayBadData()
        {
            var receivePort = 141;

            var testAETConfigModel = GetTestAETConfigModel();

            using (var segmentationClient = GetMockInnerEyeSegmentationClient())
                using (var deleteService = CreateDeleteService())
                    using (var pushService = CreatePushService())
                        using (var downloadService = CreateDownloadService(segmentationClient))
                            using (var uploadService = CreateUploadService(segmentationClient))
                                using (var receiveService = CreateReceiveService(receivePort))
                                    using (var uploadQueue = receiveService.UploadQueue)
                                    {
                                        deleteService.Start();
                                        pushService.Start();
                                        downloadService.Start();
                                        uploadService.Start();
                                        receiveService.Start();

                                        DcmtkHelpers.SendFileUsingDCMTK(
                                            @"Images\LargeSeriesWithContour\rtstruct.dcm",
                                            receivePort,
                                            ScuProfile.LEExplicitCT,
                                            TestContext,
                                            applicationEntityTitle: testAETConfigModel.CallingAET,
                                            calledAETitle: testAETConfigModel.CalledAET);

                                        await Task.Delay(1000).ConfigureAwait(false);

                                        WaitUntilNoMessagesOnQueue(uploadQueue);

                                        Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue));
                                    }
        }
コード例 #2
0
        public void ReceiveServiceAPIDownTest()
        {
            var callingAet = "ProstateRTMl";

            var mockReceiverConfigurationProvider = new MockConfigurationProvider <ReceiveServiceConfig>();
            var client = GetMockInnerEyeSegmentationClient();

            var gatewayReceiveConfig = GetTestGatewayReceiveServiceConfig(140);

            mockReceiverConfigurationProvider.ConfigurationQueue.Clear();
            mockReceiverConfigurationProvider.ConfigurationQueue.Enqueue(gatewayReceiveConfig);

            using (var receiveService = CreateReceiveService(mockReceiverConfigurationProvider.GetConfiguration))
                using (var uploadQueue = receiveService.UploadQueue)
                {
                    receiveService.Start();

                    // This should cause an exception to be raised in ReceiveService.GetAcceptedSopClassesAndTransferSyntaxes
                    mockReceiverConfigurationProvider.TestException = new Exception("A general exception.");

                    uploadQueue.Clear();

                    DcmtkHelpers.SendFileUsingDCMTK(
                        @"Images\1ValidSmall\1.dcm",
                        gatewayReceiveConfig.GatewayDicomEndPoint.Port,
                        ScuProfile.LEExplicitCT,
                        TestContext,
                        applicationEntityTitle: callingAet,
                        calledAETitle: gatewayReceiveConfig.GatewayDicomEndPoint.Title);

                    var receiveQueueItem = TransactionalDequeue <UploadQueueItem>(uploadQueue, 10000);

                    Assert.IsNotNull(receiveQueueItem);
                    Assert.AreEqual(callingAet, receiveQueueItem.CallingApplicationEntityTitle);
                    Assert.AreEqual(gatewayReceiveConfig.GatewayDicomEndPoint.Title, receiveQueueItem.CalledApplicationEntityTitle);

                    Assert.IsFalse(string.IsNullOrEmpty(receiveQueueItem.AssociationFolderPath));

                    var saveDirectoryInfo = new DirectoryInfo(receiveQueueItem.AssociationFolderPath);

                    Assert.IsTrue(saveDirectoryInfo.Exists);

                    var files = saveDirectoryInfo.GetFiles();

                    // Check we received one file over this association
                    Assert.AreEqual(1, files.Length);

                    // Attempt to get another item from the queue
                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue));
                }
        }
コード例 #3
0
        public async Task DicomDataReceiverServerStarts()
        {
            var applicationEntity = new GatewayApplicationEntity("RListenerTest", 191, "127.0.0.1");
            var resultsDirectory  = CreateTemporaryDirectory();

            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultsDirectory.FullName)))
            {
                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                var eventCount = 0;
                var folderPath = string.Empty;

                dicomDataReceiver.DataReceived += (sender, e) =>
                {
                    folderPath = e.FolderPath;
                    Interlocked.Increment(ref eventCount);
                };

                Assert.ThrowsException <DicomNetworkException>(() => StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port));

                var dataSender = new DicomDataSender();
                var echoResult = await dataSender.DicomEchoAsync(
                    "RListener",
                    applicationEntity.Title,
                    applicationEntity.Port,
                    applicationEntity.IpAddress);

                // Check echo
                Assert.IsTrue(echoResult == DicomOperationResult.Success);

                DcmtkHelpers.SendFileUsingDCMTK(
                    @"Images\1ValidSmall\1.dcm",
                    applicationEntity.Port,
                    ScuProfile.LEExplicitCT,
                    TestContext);

                // Wait for all events to finish on the data received
                SpinWait.SpinUntil(() => eventCount >= 3, TimeSpan.FromSeconds(10));

                // Check the file exists
                Assert.IsTrue(File.Exists(Path.Combine(folderPath, @"1.2.840.113619.2.81.290.1.36662.3.1.20151027.220159.dcm")));

                dicomDataReceiver.StopServer();
            }
        }
コード例 #4
0
        public async Task ReceiveServiceEchoTest()
        {
            var testAETConfigModel = GetTestAETConfigModel();
            var receivePort        = 180;

            using (var receiveService = CreateReceiveService(receivePort))
                using (var uploadQueue = receiveService.UploadQueue)
                {
                    uploadQueue.Clear();
                    receiveService.Start();

                    var sender = new DicomDataSender();

                    await sender.DicomEchoAsync(
                        "Hello",
                        testAETConfigModel.CalledAET,
                        receivePort,
                        "127.0.0.1").ConfigureAwait(false);

                    // Check nothing is added to the message queue
                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue, timeoutMs: 1000));

                    // Now check when we send a file a message is added
                    DcmtkHelpers.SendFileUsingDCMTK(
                        @"Images\1ValidSmall\1.dcm",
                        receivePort,
                        ScuProfile.LEExplicitCT,
                        TestContext,
                        applicationEntityTitle: testAETConfigModel.CallingAET,
                        calledAETitle: testAETConfigModel.CalledAET);

                    Assert.IsNotNull(TransactionalDequeue <UploadQueueItem>(uploadQueue, timeoutMs: 1000));

                    // Now try another Dicom echo
                    await sender.DicomEchoAsync(
                        "Hello",
                        testAETConfigModel.CalledAET,
                        receivePort,
                        "127.0.0.1").ConfigureAwait(false);

                    // Check nothing is added to the message queue
                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue, timeoutMs: 1000));
                }
        }
コード例 #5
0
        public void DicomDataReceiverMutlipleAssociations()
        {
            const int numberOfAssociations = 10;
            const int port = 122;

            var applicationEntity = new GatewayApplicationEntity("RListenerTest", port, "127.0.0.1");
            var resultsDirectory  = CreateTemporaryDirectory();

            using (var dicomDataReceiver = new ListenerDataReceiver(new ListenerDicomSaver(resultsDirectory.FullName)))
            {
                StartDicomDataReceiver(dicomDataReceiver, applicationEntity.Port);

                var associationsReceivedCount = 0;
                var receivedAssociations      = new string[numberOfAssociations];

                dicomDataReceiver.DataReceived += (sender, e) =>
                {
                    if (e.ProgressCode == DicomReceiveProgressCode.AssociationEstablished)
                    {
                        receivedAssociations[int.Parse(e.DicomAssociation.CallingAE)] = e.DicomAssociation.CallingAE;
                        Interlocked.Increment(ref associationsReceivedCount);
                    }
                };

                Parallel.For(0, numberOfAssociations, i =>
                {
                    var dcmtkResult = DcmtkHelpers.SendFileUsingDCMTK(
                        @"Images\1ValidSmall\1.dcm",
                        port,
                        ScuProfile.LEExplicitCT,
                        TestContext,
                        waitForExit: false,
                        applicationEntityTitle: i.ToString());
                });

                SpinWait.SpinUntil(() => associationsReceivedCount == numberOfAssociations, TimeSpan.FromMinutes(1));

                for (var i = 0; i < numberOfAssociations; i++)
                {
                    Assert.IsTrue(receivedAssociations[i] == i.ToString());
                }
            }
        }
コード例 #6
0
        public void ReceiveServiceLiveEndToEndTest()
        {
            var receivePort = 160;

            var callingAet = "ProstateRTMl";
            var calledAet  = "testname";

            using (var receiveService = CreateReceiveService(receivePort))
                using (var uploadQueue = receiveService.UploadQueue)
                {
                    uploadQueue.Clear();    // Clear the message queue
                    receiveService.Start(); // Start the service

                    DcmtkHelpers.SendFileUsingDCMTK(
                        @"Images\1ValidSmall\1.dcm",
                        receivePort,
                        ScuProfile.LEExplicitCT,
                        TestContext,
                        applicationEntityTitle: callingAet,
                        calledAETitle: calledAet);

                    var receiveQueueItem = TransactionalDequeue <UploadQueueItem>(uploadQueue, timeoutMs: 20 * 1000);

                    Assert.IsNotNull(receiveQueueItem);
                    Assert.AreEqual(callingAet, receiveQueueItem.CallingApplicationEntityTitle);
                    Assert.AreEqual(calledAet, receiveQueueItem.CalledApplicationEntityTitle);

                    Assert.IsFalse(string.IsNullOrEmpty(receiveQueueItem.AssociationFolderPath));

                    var saveDirectoryInfo = new DirectoryInfo(receiveQueueItem.AssociationFolderPath);

                    Assert.IsTrue(saveDirectoryInfo.Exists);

                    var files = saveDirectoryInfo.GetFiles();

                    // Check we received one file over this association
                    Assert.AreEqual(1, files.Length);

                    // Attempt to get another item from the queue
                    Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue));
                }
        }
コード例 #7
0
        public void ReceiveServiceRestartTest()
        {
            var testAETConfigModel = GetTestAETConfigModel();

            var configurationDirectory = CreateTemporaryDirectory().FullName;

            var expectedGatewayReceiveConfig1 = TestGatewayReceiveConfigProvider.Config.With(
                receiveServiceConfig: GetTestGatewayReceiveServiceConfig(110),
                configurationServiceConfig: new ConfigurationServiceConfig(
                    configurationRefreshDelaySeconds: 1));

            ConfigurationProviderTests.Serialise(expectedGatewayReceiveConfig1, configurationDirectory, GatewayReceiveConfigProvider.GatewayReceiveConfigFileName);

            using (var client = GetMockInnerEyeSegmentationClient())
                using (var gatewayReceiveConfigProvider = CreateGatewayReceiveConfigProvider(configurationDirectory))
                    using (var receiveService = CreateReceiveService(gatewayReceiveConfigProvider.ReceiveServiceConfig))
                        using (var uploadQueue = receiveService.UploadQueue)
                            using (var configurationService = CreateConfigurationService(
                                       client,
                                       gatewayReceiveConfigProvider.ConfigurationServiceConfig,
                                       receiveService))
                            {
                                // Start the service
                                configurationService.Start();

                                uploadQueue.Clear(); // Clear the message queue

                                var expectedGatewayReceiveConfig2 = TestGatewayReceiveConfigProvider.Config.With(
                                    receiveServiceConfig: GetTestGatewayReceiveServiceConfig(111),
                                    configurationServiceConfig: new ConfigurationServiceConfig(
                                        expectedGatewayReceiveConfig1.ConfigurationServiceConfig.ConfigCreationDateTime.AddSeconds(5),
                                        expectedGatewayReceiveConfig1.ConfigurationServiceConfig.ApplyConfigDateTime.AddSeconds(10)));

                                ConfigurationProviderTests.Serialise(expectedGatewayReceiveConfig2, configurationDirectory, GatewayReceiveConfigProvider.GatewayReceiveConfigFileName);

                                SpinWait.SpinUntil(() => receiveService.StartCount == 2);

                                // Send on the old config
                                var result = DcmtkHelpers.SendFileUsingDCMTK(
                                    @"Images\1ValidSmall\1.dcm",
                                    expectedGatewayReceiveConfig1.ReceiveServiceConfig.GatewayDicomEndPoint.Port,
                                    ScuProfile.LEExplicitCT,
                                    TestContext,
                                    applicationEntityTitle: testAETConfigModel.CallingAET,
                                    calledAETitle: testAETConfigModel.CalledAET);

                                // Check this did not send on the old config
                                Assert.IsFalse(string.IsNullOrWhiteSpace(result));

                                // Send on the new config
                                result = DcmtkHelpers.SendFileUsingDCMTK(
                                    @"Images\1ValidSmall\1.dcm",
                                    expectedGatewayReceiveConfig2.ReceiveServiceConfig.GatewayDicomEndPoint.Port,
                                    ScuProfile.LEExplicitCT,
                                    TestContext,
                                    applicationEntityTitle: testAETConfigModel.CallingAET,
                                    calledAETitle: testAETConfigModel.CalledAET);

                                // Check this did send on the new config
                                Assert.IsTrue(string.IsNullOrWhiteSpace(result));

                                var receiveQueueItem = TransactionalDequeue <UploadQueueItem>(uploadQueue);

                                Assert.IsNotNull(receiveQueueItem);
                                Assert.AreEqual(testAETConfigModel.CallingAET, receiveQueueItem.CallingApplicationEntityTitle);
                                Assert.AreEqual(testAETConfigModel.CalledAET, receiveQueueItem.CalledApplicationEntityTitle);

                                Assert.IsFalse(string.IsNullOrEmpty(receiveQueueItem.AssociationFolderPath));

                                var saveDirectoryInfo = new DirectoryInfo(receiveQueueItem.AssociationFolderPath);

                                Assert.IsTrue(saveDirectoryInfo.Exists);

                                var files = saveDirectoryInfo.GetFiles();

                                // Check we received one file over this association
                                Assert.AreEqual(1, files.Length);

                                // Attempt to get another item from the queue
                                Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue));
                            }
        }
コード例 #8
0
        public void ReceiveServiceRestartTest()
        {
            var callingAet = "ProstateRTMl";

            var client = GetMockInnerEyeSegmentationClient();


            var mockConfigurationServiceConfigProvider = new MockConfigurationProvider <ConfigurationServiceConfig>();

            var configurationServiceConfig1 = new ConfigurationServiceConfig(
                configurationRefreshDelaySeconds: 1);

            var configurationServiceConfig2 = new ConfigurationServiceConfig(
                configurationServiceConfig1.ConfigCreationDateTime.AddSeconds(5),
                configurationServiceConfig1.ApplyConfigDateTime.AddSeconds(10));

            mockConfigurationServiceConfigProvider.ConfigurationQueue.Clear();
            mockConfigurationServiceConfigProvider.ConfigurationQueue.Enqueue(configurationServiceConfig1);
            mockConfigurationServiceConfigProvider.ConfigurationQueue.Enqueue(configurationServiceConfig2);

            var mockReceiverConfigurationProvider2 = new MockConfigurationProvider <ReceiveServiceConfig>();

            var testReceiveServiceConfig1 = GetTestGatewayReceiveServiceConfig(110);
            var testReceiveServiceConfig2 = GetTestGatewayReceiveServiceConfig(111);

            mockReceiverConfigurationProvider2.ConfigurationQueue.Clear();
            mockReceiverConfigurationProvider2.ConfigurationQueue.Enqueue(testReceiveServiceConfig1);
            mockReceiverConfigurationProvider2.ConfigurationQueue.Enqueue(testReceiveServiceConfig2);

            using (var receiveService = CreateReceiveService(mockReceiverConfigurationProvider2.GetConfiguration))
                using (var uploadQueue = receiveService.UploadQueue)
                    using (var configurationService = CreateConfigurationService(
                               client,
                               mockConfigurationServiceConfigProvider.GetConfiguration,
                               receiveService))
                    {
                        // Start the service
                        configurationService.Start();

                        uploadQueue.Clear(); // Clear the message queue

                        SpinWait.SpinUntil(() => receiveService.StartCount == 2);

                        // Send on the new config
                        var result = DcmtkHelpers.SendFileUsingDCMTK(
                            @"Images\1ValidSmall\1.dcm",
                            testReceiveServiceConfig1.GatewayDicomEndPoint.Port,
                            ScuProfile.LEExplicitCT,
                            TestContext,
                            applicationEntityTitle: callingAet,
                            calledAETitle: testReceiveServiceConfig1.GatewayDicomEndPoint.Title);

                        // Check this did send on the old config
                        Assert.IsFalse(string.IsNullOrWhiteSpace(result));

                        // Send on the new config
                        result = DcmtkHelpers.SendFileUsingDCMTK(
                            @"Images\1ValidSmall\1.dcm",
                            testReceiveServiceConfig2.GatewayDicomEndPoint.Port,
                            ScuProfile.LEExplicitCT,
                            TestContext,
                            applicationEntityTitle: callingAet,
                            calledAETitle: testReceiveServiceConfig2.GatewayDicomEndPoint.Title);

                        // Check this did send on the new config
                        Assert.IsTrue(string.IsNullOrWhiteSpace(result));

                        var receiveQueueItem = TransactionalDequeue <UploadQueueItem>(uploadQueue);

                        Assert.IsNotNull(receiveQueueItem);
                        Assert.AreEqual(callingAet, receiveQueueItem.CallingApplicationEntityTitle);
                        Assert.AreEqual(testReceiveServiceConfig2.GatewayDicomEndPoint.Title, receiveQueueItem.CalledApplicationEntityTitle);

                        Assert.IsFalse(string.IsNullOrEmpty(receiveQueueItem.AssociationFolderPath));

                        var saveDirectoryInfo = new DirectoryInfo(receiveQueueItem.AssociationFolderPath);

                        Assert.IsTrue(saveDirectoryInfo.Exists);

                        var files = saveDirectoryInfo.GetFiles();

                        // Check we received one file over this association
                        Assert.AreEqual(1, files.Length);

                        // Attempt to get another item from the queue
                        Assert.ThrowsException <MessageQueueReadException>(() => TransactionalDequeue <UploadQueueItem>(uploadQueue));
                    }
        }