public CommandResponse Handle(TestCommands.Command3 command) { SpinWait.SpinUntil(() => false, 500); return(command.Succeed()); }
public async Task If_deleted_original_index_on_destination_but_not_side_by_side_index() { using (var source = CreateStore()) using (var destination = CreateStore()) { var sourceDatabase = await servers[0].Server.GetDatabaseInternal(source.DefaultDatabase); var destinationDatabase = await servers[1].Server.GetDatabaseInternal(destination.DefaultDatabase); sourceDatabase.StopBackgroundWorkers(); destinationDatabase.StopBackgroundWorkers(); var testIndex = new UserIndex(); var oldIndexDef = new IndexDefinition { Map = "from user in docs.Users\n select new {\n\tName = user.Name\n}" }; source.DatabaseCommands.PutIndex(testIndex.IndexName, oldIndexDef); using (var session = source.OpenSession()) { session.Store(new User { Name = "John Doe" }); session.SaveChanges(); } var sourceReplicationTask = sourceDatabase.StartupTasks.OfType <ReplicationTask>().First(); sourceReplicationTask.Pause(); SetupReplication(source.DatabaseCommands, destination); sourceReplicationTask.IndexReplication.Execute(); //replicate the usual index source.SideBySideExecuteIndex(testIndex); //the side by side index will be automatically replicated SpinWait.SpinUntil(() => { var index = destinationDatabase.Indexes.GetIndexDefinition(Constants.SideBySideIndexNamePrefix + testIndex.IndexName); return(index != null); }, 5000); Assert.NotNull(destinationDatabase.Indexes.GetIndexDefinition(Constants.SideBySideIndexNamePrefix + testIndex.IndexName)); destinationDatabase.Indexes.DeleteIndex(testIndex.IndexName); //delete the original index var sideBySideIndex = destinationDatabase.Indexes.GetIndexDefinition(Constants.SideBySideIndexNamePrefix + testIndex.IndexName); Assert.NotNull(sideBySideIndex); VerifyReplacementDocumentIsThere(Constants.SideBySideIndexNamePrefix + testIndex.IndexName, destinationDatabase); sourceReplicationTask.IndexReplication.Execute(); destinationDatabase.SpinBackgroundWorkers(); WaitForIndexing(destination); //wait until the index will be replaced SpinWait.SpinUntil(() => { var index = destinationDatabase.Indexes.GetIndexDefinition(testIndex.IndexName); return(index != null); }, 15000); var oldIndex = destinationDatabase.Indexes.GetIndexDefinition(testIndex.IndexName); Assert.True(oldIndex.Equals(testIndex.CreateIndexDefinition(), false)); sideBySideIndex = destinationDatabase.Indexes.GetIndexDefinition(Constants.SideBySideIndexNamePrefix + testIndex.IndexName); Assert.Null(sideBySideIndex); SpinWait.SpinUntil(() => { var doc = destinationDatabase.Documents.Get(Constants.IndexReplacePrefix + Constants.SideBySideIndexNamePrefix + testIndex.IndexName, null); return(doc == null); }, 5000); Assert.Null(destinationDatabase.Documents.Get(Constants.IndexReplacePrefix + Constants.SideBySideIndexNamePrefix + testIndex.IndexName, null)); } }
public static void CheckImagesForMatch(List <ImgDataType> imageList, int startAt, int endAt, double pixelErrorRate = .15, double picturePassingRate = .9) { Bitmap leftImg = null; //init type pointer for (int i = startAt; i < endAt; i++) //in all the megumin pics from the list { SpinWait.SpinUntil(delegate { try { leftImg = (Bitmap)Image.FromFile(imageList.ElementAt(i).fileLocation); //load one img into the memory } catch { return(false); } return(true); }); Console.WriteLine("------------------------------------"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Testing for: {0}\n", imageList.ElementAt(i).fileLocation); Console.ResetColor(); for (int j = 0; j < imageList.Count; j++)//foreach (ImgDataType imageList.ElementAt(i) in imageList) // start interating in the list once again { Bitmap rightImg = null; if (!checkFileIfSame(imageList.ElementAt(i).fileLocation, imageList.ElementAt(j).fileLocation)) // is this the same picture? { if (imageList.ElementAt(i).ratio == imageList.ElementAt(j).ratio) // is the size ratio the same, meaning can we compare these? { SpinWait.SpinUntil(delegate { try { rightImg = (Bitmap)Image.FromFile(imageList.ElementAt(j).fileLocation); //load in the pic we want to compare with } catch { return(false); } return(true); }); rightImg = ResizeImage(rightImg, imageList.ElementAt(i).picWidth, imageList.ElementAt(i).picHeight); //resize it so the size equals with the other picture we compare with double sumAvgDiff = 0; int badPixel = 0; int AllPixelCount = imageList.ElementAt(i).picWidth *imageList.ElementAt(i).picHeight; for (int k = 0; k < imageList.ElementAt(i).picWidth; k++) // we suppose they have the same height and width { for (int l = 0; l < imageList.ElementAt(i).picHeight; l++) { Color leftColor = leftImg.GetPixel(k, l); //get comparer color Color rightColor = rightImg.GetPixel(k, l); //get comparee color double redDiff = Math.Abs(leftColor.R - rightColor.R) / 255.0; //get the difference for all colors in percentage double greenDiff = Math.Abs(leftColor.G - rightColor.G) / 255.0; double blueDiff = Math.Abs(leftColor.B - rightColor.B) / 255.0; double avgDiff = (redDiff + greenDiff + blueDiff) / 3.0; if (avgDiff > pixelErrorRate) // test pixel if the difference is bigger than x% { badPixel++; //if not, increase the number of good pixels for match } } if (badPixel > (1.0 - picturePassingRate) * AllPixelCount) { break; } } sumAvgDiff = (double)badPixel / ((double)AllPixelCount); //get in percentage the good pixels on the comparee picture if (sumAvgDiff > picturePassingRate) { Console.WriteLine("{0}\nMatch: {1}\n\n\n", imageList.ElementAt(j).fileLocation, sumAvgDiff); if (sumAvgDiff == 1) { imageList.ElementAt(j).markedForDeletion = true; } else { findings.Add(imageList.ElementAt(i).fileLocation); findings.Add(imageList.ElementAt(j).fileLocation); findings.Add(sumAvgDiff.ToString()); } } } } else { imageList.ElementAt(j).markedForDeletion = true; } } } }
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)); } }