public void TestNoBroker() { var config = new ProducerConfig(); config.Brokers = TestUtils.GetBrokerListFromConfigs(this.props); // create topic metadata with 0 partitions var topic1Metadata = new TopicMetadata("topic1", new List <PartitionMetadata>()); var topicPartitionInfos = new Dictionary <string, TopicMetadata> { { "topic1", topic1Metadata } }; var producerPool = new ProducerPool(config); var producerDataList = new List <KeyedMessage <string, string> >(); producerDataList.Add(new KeyedMessage <string, string>("topic1", "msg1")); var handler = new DefaultEventHandler <string, string>( config, null, new StringEncoder(), new StringEncoder(), producerPool, topicPartitionInfos); try { handler.Handle(producerDataList); Assert.True(false, "Should fail with FailedToSendMessageException"); } catch (FailedToSendMessageException) { // expted } }
public void TestInvalidPartition() { var producerDataList = new List <KeyedMessage <string, Message> >(); producerDataList.Add(new KeyedMessage <string, Message>("topic1", "key1", new Message(Encoding.UTF8.GetBytes("msg1")))); var config = new ProducerConfig(); config.Brokers = TestUtils.GetBrokerListFromConfigs(this.props); // form expected partitions metadata var topic1Metadata = this.GetTopicMetadata("topic1", 0, 0, "localhost", 9092); var topicPartitionInfos = new Dictionary <string, TopicMetadata> { { "topic1", topic1Metadata } }; var producerPool = new ProducerPool(config); var handler = new DefaultEventHandler <string, string>( config, new NegativePartitioner(), null, null, producerPool, topicPartitionInfos); try { handler.PartitionAndCollate(producerDataList); } catch { Assert.False(true, "Should not throw any exception"); } }
public void TestSerializeEvents() { var produceData = TestUtils.GetMsgStrings(5).Select(m => new KeyedMessage <string, string>("topic1", m)).ToList(); var config = new ProducerConfig(); config.Brokers = TestUtils.GetBrokerListFromConfigs(this.props); // form expected partitions metadata var topic1Metadata = this.GetTopicMetadata("topic1", 0, 0, "localhost", 9092); var topicPartitionInfos = new Dictionary <string, TopicMetadata> { { "topic1", topic1Metadata } }; var producerPool = new ProducerPool(config); var handler = new DefaultEventHandler <string, string>( config, null, new StringEncoder(), new StringEncoder(), producerPool, topicPartitionInfos); var serializedData = handler.Serialize(produceData); var deserializedData = serializedData.Select( d => new KeyedMessage <string, string>(d.Topic, Util.ReadString(d.Message.Payload))).ToList(); TestUtils.CheckEquals(produceData.GetEnumerator(), deserializedData.GetEnumerator()); }
private void Btn_Recovery_Click(object sender, EventArgs e) { string fileaddress = tb_RecoveryAddress.Text.Trim(); btn_Recovery.Enabled = false; DefaultEventHandler deh = Recovery; deh.BeginInvoke(fileaddress, null, null); }
public void Should_Fire_OnDocumentSavingEvent_AndReturnCorrectData() { var document1 = new HtmlDocument(); document1.DocumentNode.AppendChild(HtmlNode.CreateNode("<title>zzz</title>")); document1.DocumentNode.AppendChild(HtmlNode.CreateNode("<body>zzz</body>")); var page1 = new PageData { AbsolutePath = "/test-on-document-saving", Content = document1, Id = Guid.NewGuid(), IsPublished = true }; Document document = null; DefaultEventHandler <DocumentSavingEventArgs> onDocumentSaving = args => { args.Document.Add(new Field("TestLuceneField", "TestLuceneFieldValue", Field.Store.YES, Field.Index.ANALYZED)); }; DefaultEventHandler <SearchResultRetrievingEventArgs> onSearchResultRetrieving = args => { Assert.AreEqual(args.Documents.Count(), 1); Assert.AreEqual(args.ResultItems.Count(), 1); document = args.Documents[0]; }; DefaultEventHandler <SearchQueryExecutingEventArgs> onSearchQueryExecuting = args => { Assert.AreEqual(args.RequestQuery, "Nonsense with no results"); args.Query = new TermQuery(new Term("content", "zzz")); }; Events.LuceneEvents.Instance.DocumentSaving += onDocumentSaving; Events.LuceneEvents.Instance.SearchResultRetrieving += onSearchResultRetrieving; Events.LuceneEvents.Instance.SearchQueryExecuting += onSearchQueryExecuting; var service = new DefaultIndexerService(Container.Resolve <ICmsConfiguration>(), Container.Resolve <IRepository>(), Container.Resolve <ISecurityService>(), Container.Resolve <IAccessControlService>()); if (service.OpenWriter()) { service.AddHtmlDocument(page1); service.CloseWriter(); } var results = service.Search(new SearchRequest("Nonsense with no results")); Assert.IsNotNull(results); Assert.IsNotNull(results.Items); Assert.IsNotNull(document); Assert.AreEqual(document.Get("TestLuceneField"), "TestLuceneFieldValue"); Events.LuceneEvents.Instance.DocumentSaving -= onDocumentSaving; Events.LuceneEvents.Instance.SearchResultRetrieving -= onSearchResultRetrieving; Events.LuceneEvents.Instance.SearchQueryExecuting -= onSearchQueryExecuting; }
private static IHandleEvents <TAggregate> GetOrCreateHandler <TAggregate>() { lock (EventHandlersLock) { object handler; var isCached = CachedEventHandlers.TryGetValue(typeof(TAggregate), out handler); handler = new DefaultEventHandler <TAggregate>(); if (!isCached) { CachedEventHandlers.Add(typeof(TAggregate), handler); } return((IHandleEvents <TAggregate>)handler); } }
public void TestRandomPartitioner() { var config = new ProducerConfig(); config.Brokers = TestUtils.GetBrokerListFromConfigs(this.props); // create topic metadata with 0 partitions var topic1Metadata = this.GetTopicMetadata("topic1", 0, 0, "localhost", 9092); var topic2Metadata = this.GetTopicMetadata("topic2", 0, 0, "localhost", 9092); var topicPartitionInfos = new Dictionary <string, TopicMetadata> { { "topic1", topic1Metadata }, { "topic2", topic2Metadata } }; var producerPool = new ProducerPool(config); var handler = new DefaultEventHandler <string, string>( config, null, null, null, producerPool, topicPartitionInfos); var producerDataList = new List <KeyedMessage <string, Message> >(); producerDataList.Add(new KeyedMessage <string, Message>("topic1", new Message(Encoding.UTF8.GetBytes("msg1")))); producerDataList.Add(new KeyedMessage <string, Message>("topic2", new Message(Encoding.UTF8.GetBytes("msg2")))); producerDataList.Add(new KeyedMessage <string, Message>("topic1", new Message(Encoding.UTF8.GetBytes("msg3")))); var partitionedDataOpt = handler.PartitionAndCollate(producerDataList); if (partitionedDataOpt != null) { foreach (var brokerAndData in partitionedDataOpt) { var dataPerBroker = brokerAndData.Value; foreach (var topicPartitionData in dataPerBroker) { var partitionId = topicPartitionData.Key.Partiton; Assert.True(partitionId == 0); } } } else { Assert.False(true, "Failed to collate requests by topic, partition"); } }
public void AddTokenGet(DefaultEventHandler eventHandler) => ((MainPage)MainPage).TokenGet += eventHandler;
public void AddLocalNotify(DefaultEventHandler eventHandler) => ((MainPage)MainPage).LocalNotify += eventHandler;
public void TestPartitionAndCollateEvents() { var producerDataList = new List <KeyedMessage <int, Message> >(); // use bogus key and partition key override for some messages producerDataList.Add(new KeyedMessage <int, Message>("topic1", 0, new Message(Encoding.UTF8.GetBytes("msg1")))); producerDataList.Add(new KeyedMessage <int, Message>("topic2", -99, 1, new Message(Encoding.UTF8.GetBytes("msg2")))); producerDataList.Add(new KeyedMessage <int, Message>("topic1", 2, new Message(Encoding.UTF8.GetBytes("msg3")))); producerDataList.Add(new KeyedMessage <int, Message>("topic1", -101, 3, new Message(Encoding.UTF8.GetBytes("msg4")))); producerDataList.Add(new KeyedMessage <int, Message>("topic2", 4, new Message(Encoding.UTF8.GetBytes("msg5")))); var broker1 = new Broker(0, "localhost", 9092); var broker2 = new Broker(1, "localhost", 9093); // form expected partitions metadata var partition1Metadata = new PartitionMetadata(0, broker1, new List <Broker> { broker1, broker2 }); var partition2Metadata = new PartitionMetadata(1, broker2, new List <Broker> { broker1, broker2 }); var topic1Metadata = new TopicMetadata( "topic1", new List <PartitionMetadata> { partition1Metadata, partition2Metadata }); var topic2Metadata = new TopicMetadata( "topic2", new List <PartitionMetadata> { partition1Metadata, partition2Metadata }); var topicPartitionInfos = new Dictionary <string, TopicMetadata> { { "topic1", topic1Metadata }, { "topic2", topic2Metadata } }; var intPartitioner = new IntPartitioner(); var config = new ProducerConfig(); config.Brokers = TestUtils.GetBrokerListFromConfigs(this.props); var producerPool = new ProducerPool(config); var handler = new DefaultEventHandler <int, string>( config, intPartitioner, null, new IntEncoder(), producerPool, topicPartitionInfos); var topic1Broker1Data = new List <KeyedMessage <int, Message> > { new KeyedMessage <int, Message>( "topic1", 0, new Message( Encoding.UTF8.GetBytes("msg1"))), new KeyedMessage <int, Message>( "topic1", 2, new Message( Encoding.UTF8.GetBytes("msg3"))) }; var topic1Broker2Data = new List <KeyedMessage <int, Message> > { new KeyedMessage <int, Message>( "topic1", -101, 3, new Message( Encoding.UTF8.GetBytes("msg4"))) }; var topic2Broker1Data = new List <KeyedMessage <int, Message> > { new KeyedMessage <int, Message>( "topic2", 4, new Message( Encoding.UTF8.GetBytes("msg5"))) }; var topic2Broker2Data = new List <KeyedMessage <int, Message> > { new KeyedMessage <int, Message>( "topic2", -99, 1, new Message( Encoding.UTF8.GetBytes("msg2"))) }; var expectedResult = new Dictionary <int, Dictionary <TopicAndPartition, List <KeyedMessage <int, Message> > > > { { 0, new Dictionary <TopicAndPartition, List <KeyedMessage <int, Message> > > { { new TopicAndPartition("topic1", 0), topic1Broker1Data }, { new TopicAndPartition("topic2", 0), topic2Broker1Data } } }, { 1, new Dictionary <TopicAndPartition, List <KeyedMessage <int, Message> > > { { new TopicAndPartition("topic1", 1), topic1Broker2Data }, { new TopicAndPartition("topic2", 1), topic2Broker2Data } } }, }; var actualResut = handler.PartitionAndCollate(producerDataList); Assert.Equal(expectedResult.Count, actualResut.Count); Assert.True(expectedResult.Keys.SequenceEqual(actualResut.Keys)); foreach (var key in expectedResult.Keys) { var exptectedInnerDict = expectedResult[key]; var actualInnerDict = actualResut[key]; Assert.Equal(exptectedInnerDict.Count, actualInnerDict.Count); foreach (var topicAndPartition in exptectedInnerDict.Keys) { var exptectedKeyedMsgs = exptectedInnerDict[topicAndPartition]; var actualKeyedMsgs = actualInnerDict[topicAndPartition]; Assert.True(exptectedKeyedMsgs.SequenceEqual(actualKeyedMsgs)); } } }
private void before_each() { _aggregate = new FakeAggregate(); _target = new DefaultEventHandler(); }