public AParser() : base(ImmutableSortedSet.Create <Expected <TToken> >()) { }
internal async Task PublishDiagnosticsAsync(Document document) { // Retrieve all diagnostics for the current document grouped by their actual file uri. var fileUriToDiagnostics = await GetDiagnosticsAsync(document, CancellationToken.None).ConfigureAwait(false); // Get the list of file uris with diagnostics (for the document). // We need to join the uris from current diagnostics with those previously published // so that we clear out any diagnostics in mapped files that are no longer a part // of the current diagnostics set (because the diagnostics were fixed). // Use sorted set to have consistent publish ordering for tests and debugging. var urisForCurrentDocument = _documentsToPublishedUris.GetOrValue(document.Id, ImmutableSortedSet.Create <Uri>(s_uriComparer)).Union(fileUriToDiagnostics.Keys); // Update the mapping for this document to be the uris we're about to publish diagnostics for. _documentsToPublishedUris[document.Id] = urisForCurrentDocument; // Go through each uri and publish the updated set of diagnostics per uri. foreach (var fileUri in urisForCurrentDocument) { // Get the updated diagnostics for a single uri that were contributed by the current document. var diagnostics = fileUriToDiagnostics.GetOrValue(fileUri, ImmutableArray <LanguageServer.Protocol.Diagnostic> .Empty); if (_publishedFileToDiagnostics.ContainsKey(fileUri)) { // Get all previously published diagnostics for this uri excluding those that were contributed from the current document. // We don't need those since we just computed the updated values above. var diagnosticsFromOtherDocuments = _publishedFileToDiagnostics[fileUri].Where(kvp => kvp.Key != document.Id).SelectMany(kvp => kvp.Value); // Since diagnostics are replaced per uri, we must publish both contributions from this document and any other document // that has diagnostic contributions to this uri, so union the two sets. diagnostics = diagnostics.AddRange(diagnosticsFromOtherDocuments); } await SendDiagnosticsNotificationAsync(fileUri, diagnostics).ConfigureAwait(false); // There are three cases here -> // 1. There are no diagnostics to publish for this fileUri. We no longer need to track the fileUri at all. // 2. There are diagnostics from the current document. Store the diagnostics for the fileUri and document // so they can be published along with contributions to the fileUri from other documents. // 3. There are no diagnostics contributed by this document to the fileUri (could be some from other documents). // We should clear out the diagnostics for this document for the fileUri. if (diagnostics.IsEmpty) { // We published an empty set of diagnostics for this uri. We no longer need to keep track of this mapping // since there will be no previous diagnostics that we need to clear out. _documentsToPublishedUris.MultiRemove(document.Id, fileUri); // There are not any diagnostics to keep track of for this file, so we can stop. _publishedFileToDiagnostics.Remove(fileUri); } else if (fileUriToDiagnostics.ContainsKey(fileUri)) { // We do have diagnostics from the current document - update the published diagnostics map // to contain the new diagnostics contributed by this document for this uri. var documentsToPublishedDiagnostics = _publishedFileToDiagnostics.GetOrAdd(fileUri, (_) => new Dictionary <DocumentId, ImmutableArray <LanguageServer.Protocol.Diagnostic> >()); documentsToPublishedDiagnostics[document.Id] = fileUriToDiagnostics[fileUri]; } else { // There were diagnostics from other documents, but none from the current document. // If we're tracking the current document, we can stop. _publishedFileToDiagnostics.GetOrDefault(fileUri)?.Remove(document.Id); _documentsToPublishedUris.MultiRemove(document.Id, fileUri); } } }
private protected override ImmutableSortedSet <Expected <TToken> > CalculateExpected() => ImmutableSortedSet.Create <Expected <TToken> >();
public void A_gossip_must_have_leader_as_first_member_based_on_ordering_except_exiting_status() { new Gossip(ImmutableSortedSet.Create(c2, e2)).Leader(c2.UniqueAddress).Should().Be(c2.UniqueAddress); new Gossip(ImmutableSortedSet.Create(c3, e2)).Leader(c3.UniqueAddress).Should().Be(e2.UniqueAddress); new Gossip(ImmutableSortedSet.Create(c3)).Leader(c3.UniqueAddress).Should().Be(c3.UniqueAddress); }
public void A_gossip_must_not_reach_convergence_until_all_have_seen_version() { var g1 = new Gossip(ImmutableSortedSet.Create(a1, b1)).Seen(a1.UniqueAddress); g1.Convergence(a1.UniqueAddress, new HashSet <UniqueAddress>()).Should().BeFalse(); }
public void ClusterDomainEventPublisher_must_publish_role_leader_changed() { var subscriber = CreateTestProbe(); _publisher.Tell(new InternalClusterAction.Subscribe(subscriber.Ref, ClusterEvent.SubscriptionInitialStateMode.InitialStateAsSnapshot, ImmutableHashSet.Create(typeof(ClusterEvent.RoleLeaderChanged)))); subscriber.ExpectMsg <ClusterEvent.CurrentClusterState>(); _publisher.Tell(new InternalClusterAction.PublishChanges(new MembershipState(new Gossip(ImmutableSortedSet.Create(cJoining, dUp)), dUp.UniqueAddress))); subscriber.ExpectMsg(new ClusterEvent.RoleLeaderChanged("GRP", dUp.Address)); _publisher.Tell(new InternalClusterAction.PublishChanges(new MembershipState(new Gossip(ImmutableSortedSet.Create(cUp, dUp)), dUp.UniqueAddress))); subscriber.ExpectMsg(new ClusterEvent.RoleLeaderChanged("GRP", cUp.Address)); }
public override void Setup(BenchmarkContext context) { base.Setup(context); InitStreamWith(ImmutableSortedSet.Create(123, 56568, 3445, 568567, 234236, 5821, 2456, 71231)); }
public void ShouldParseCreateTable() { var tested = Parser.Parser.CreateTable.Parse(@"CREATE TABLE brand ( id SERIAL NOT NULL, name VARCHAR(50) NOT NULL, logo VARCHAR(200), archived BOOLEAN DEFAULT '0', color VARCHAR(100) NOT NULL, external_id VARCHAR(500), PRIMARY KEY (id), CONSTRAINT bibi_uk UNIQUE (name) ) "); Assert.AreEqual("brand", tested.Table); Assert.AreEqual(6, tested.ColumnDefinitions.Count); CollectionAssert.AreEqual( ImmutableList.Create( new ColumnDefinition("id", "SERIAL", "NOT NULL"), new ColumnDefinition("name", "VARCHAR", "NOT NULL"), new ColumnDefinition("logo", "VARCHAR", ""), new ColumnDefinition("archived", "BOOLEAN", "DEFAULT '0'"), new ColumnDefinition("color", "VARCHAR", "NOT NULL"), new ColumnDefinition("external_id", "VARCHAR", "") ), tested.ColumnDefinitions); tested.ConstraintDefinitions.ShouldDeepEqual(ImmutableList.Create( new ConstraintDefinition(Option <string> .None(), new PrimaryKeyConstraint(ImmutableSortedSet.Create(StringComparer.CurrentCultureIgnoreCase, "ID"))), new ConstraintDefinition("bibi_uk".ToOption(), new UniqueConstraint(ImmutableSortedSet.Create(StringComparer.CurrentCultureIgnoreCase, "name"))) )); }
public TokenParser(TToken token) : base(ImmutableSortedSet.Create(new Expected <TToken>(Rope.Create(token)))) { _token = token; }
public SortedSetReactiveCollectionSource(IComparer <T> comparer) : base(new SortedSetChangedNotification <T>(ImmutableSortedSet.Create(comparer), NotifyCollectionChangedAction.Reset, ImmutableList <T> .Empty, ImmutableList <T> .Empty, null)) { }
public void AGossipMustHaveLeaderAsFirstMemberBasedOnOrderingExceptExitingStatus() { Assert.Equal(c2.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c2, e2)).Leader); Assert.Equal(e2.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c3, e2)).Leader); Assert.Equal(c3.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c3)).Leader); }
public NegatedParser(Parser <TToken, T> parser) : base(ImmutableSortedSet.Create <Expected <TToken> >()) { _parser = parser; }
public static NonEmpty <ImmutableSortedSet <A> > sortedSet <A>(A a1, params A[] rest) => NonEmpty <ImmutableSortedSet <A> > .__unsafeNew(ImmutableSortedSet.Create(rest).Add(a1));
public static NonEmpty <ImmutableSortedSet <A> > sortedSet <A>(A a1) => NonEmpty <ImmutableSortedSet <A> > .__unsafeNew(ImmutableSortedSet.Create(a1));
static partial void CreateDefaultTemplate(ref FileSystemDirectory.Template template) { template.Children = ImmutableSortedSet.Create <FileSystemEntry>(SiblingComparer.Instance); }
public PredicateTokenParser(Func <TToken, bool> predicate) : base(ImmutableSortedSet.Create <Expected <TToken> >()) { _predicate = predicate; }
public void Reverse() { var builder = ImmutableSortedSet.Create("a", "b").ToBuilder(); Assert.Equal(new[] { "b", "a" }, builder.Reverse()); }
public void A_gossip_must_have_leader_as_first_member_based_on_ordering_except_exiting_status() { Assert.Equal(c2.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c2, e2)).Leader(c2.UniqueAddress)); Assert.Equal(e2.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c3, e2)).Leader(e2.UniqueAddress)); Assert.Equal(c3.UniqueAddress, new Gossip(ImmutableSortedSet.Create(c3)).Leader(c3.UniqueAddress)); }
public void SerializationTests_ImmutableCollections_SortedSet() { var original = ImmutableSortedSet.Create("1", "2", "3"); RoundTripCollectionSerializationTest(original); }
public RecParser(Lazy <Parser <TToken, T> > lazy) : base(ImmutableSortedSet.Create <Expected <TToken> >()) { _lazy = lazy; }
public void TestHistogramToLineData() { Assert.Equal( "!M 1493773500 #20 30 #10 5.1 \"request.latency\" source=\"appServer1\" " + "\"region\"=\"us-west\"\n", Utils.HistogramToLineData( "request.latency", ImmutableList.Create( new KeyValuePair <double, int>(30.0, 20), new KeyValuePair <double, int>(5.1, 10) ), ImmutableHashSet.Create(HistogramGranularity.Minute), 1493773500L, "appServer1", new Dictionary <string, string> { { "region", "us-west" } }.ToImmutableDictionary(), "defaultSource")); // null timestamp Assert.Equal( "!M #20 30 #10 5.1 \"request.latency\" source=\"appServer1\" " + "\"region\"=\"us-west\"\n", Utils.HistogramToLineData( "request.latency", ImmutableList.Create( new KeyValuePair <double, int>(30.0, 20), new KeyValuePair <double, int>(5.1, 10) ), ImmutableHashSet.Create(HistogramGranularity.Minute), null, "appServer1", new Dictionary <string, string> { { "region", "us-west" } }.ToImmutableDictionary(), "defaultSource")); // null tags Assert.Equal( "!M 1493773500 #20 30 #10 5.1 \"request.latency\" source=\"appServer1\"\n", Utils.HistogramToLineData( "request.latency", ImmutableList.Create( new KeyValuePair <double, int>(30.0, 20), new KeyValuePair <double, int>(5.1, 10) ), ImmutableHashSet.Create(HistogramGranularity.Minute), 1493773500L, "appServer1", null, "defaultSource")); // empty centroids Assert.Throws <ArgumentException>(() => Utils.HistogramToLineData( "request.latency", ImmutableList.Create <KeyValuePair <double, int> >(), ImmutableHashSet.Create(HistogramGranularity.Minute), 1493773500L, "appServer1", null, "defaultSource")); // no histogram granularity specified Assert.Throws <ArgumentException>(() => Utils.HistogramToLineData( "request.latency", ImmutableList.Create( new KeyValuePair <double, int>(30.0, 20), new KeyValuePair <double, int>(5.1, 10) ), ImmutableHashSet.Create <HistogramGranularity>(), 1493773500L, "appServer1", null, "defaultSource")); // multiple granularities Assert.Equal( "!M 1493773500 #20 30 #10 5.1 \"request.latency\" source=\"appServer1\" \"region\"=\"us-west\"\n" + "!H 1493773500 #20 30 #10 5.1 \"request.latency\" source=\"appServer1\" \"region\"=\"us-west\"\n" + "!D 1493773500 #20 30 #10 5.1 \"request.latency\" source=\"appServer1\" \"region\"=\"us-west\"\n", Utils.HistogramToLineData( "request.latency", ImmutableList.Create( new KeyValuePair <double, int>(30.0, 20), new KeyValuePair <double, int>(5.1, 10) ), ImmutableSortedSet.Create( HistogramGranularity.Minute, HistogramGranularity.Hour, HistogramGranularity.Day ), 1493773500L, "appServer1", new Dictionary <string, string> { { "region", "us-west" } }.ToImmutableDictionary(), "defaultSource" )); }
public ProjectTreeNodeTestBase() { this.nodeCounter = 0; this.Children = ImmutableSortedSet.Create(ProjectTreeSort.Default); }
public void A_gossip_must_not_have_Down_member_as_leader() { new Gossip(ImmutableSortedSet.Create(e3)).Leader(e3.UniqueAddress).Should().BeNull(); }
public CIStringParser(string value) : base(ImmutableSortedSet.Create(new Expected <char>(Rope.CreateRange(value)))) { _value = value.ToLowerInvariant(); }
public void A_gossip_must_reach_convergence_for_two_nodes() { var g1 = new Gossip(ImmutableSortedSet.Create(a1, b1)).Seen(a1.UniqueAddress).Seen(b1.UniqueAddress); g1.Convergence(a1.UniqueAddress, new HashSet <UniqueAddress>()).Should().BeTrue(); }
public HeartbeatNodeRing(UniqueAddress selfAddress, IEnumerable <UniqueAddress> nodes, int monitoredByNumberOfNodes) : this(selfAddress, ImmutableSortedSet.Create(nodes.ToArray()), monitoredByNumberOfNodes) { }
private protected override ImmutableSortedSet <Expected <TToken> > CalculateExpected() => ImmutableSortedSet.Create(new Expected <TToken>(Rope.Create(_token)));
public void WriteSimpleGraphNoEdges() { var graph = new Graph(new[] { new Vertex(1L, "vertex") }.ToImmutableSortedSet(), ImmutableSortedSet.Create <Edge>()); var writer = new StringWriter(); writer.WriteGraphAsTgf(graph); var reader = new StringReader(writer.ToString()); var readGraph = reader.ReadTgfGraph(); writer.Dispose(); reader.Dispose(); Assert.Equal(graph, readGraph); }
public void MemberOrdering_must_work_pick_member_with_legal_transition() { var address1 = new Address("akka.tcp", "sys1", "host1", 9001); var address2 = address1.WithPort(9002); var address3 = address1.WithPort(9003); var address4 = address1.WithPort(9004); var s1 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Joining)) .Add(TestMember.Create(address2, MemberStatus.Up, ImmutableHashSet <string> .Empty, upNumber: 1)); var s2 = ImmutableSortedSet.Create(TestMember.Create(address1, MemberStatus.Up, ImmutableHashSet <string> .Empty, upNumber: 2)); var s3 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)); var u1 = Member.PickNextTransition(s2, s1); u1.Should().BeEquivalentTo(s3); u1.Single(x => x.Address.Equals(address1)).Status.Should().Be(MemberStatus.Up); var s4 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)) .Add(TestMember.Create(address3, MemberStatus.Joining)); var s5 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)) .Add(TestMember.Create(address3, MemberStatus.Up)); var u2 = Member.PickNextTransition(s4, s1); u2.Should().BeEquivalentTo(s5); u2.Single(x => x.Address.Equals(address1)).Status.Should().Be(MemberStatus.Up); // WeaklyUp assertions var s6 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)) .Add(TestMember.Create(address3, MemberStatus.Up)) .Add(TestMember.Create(address4, MemberStatus.Joining)); var s7 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)) .Add(TestMember.Create(address3, MemberStatus.Up)) .Add(TestMember.Create(address4, MemberStatus.WeaklyUp)); var u3 = Member.PickNextTransition(s6, s7); u3.Should().BeEquivalentTo(s7); u3.Single(x => x.Address.Equals(address4)).Status.Should().Be(MemberStatus.WeaklyUp); var s8 = ImmutableSortedSet .Create(TestMember.Create(address1, MemberStatus.Up)) .Add(TestMember.Create(address2, MemberStatus.Up)) .Add(TestMember.Create(address3, MemberStatus.Up)) .Add(TestMember.Create(address4, MemberStatus.Up)); var u4 = Member.PickNextTransition(s8, s7); u4.Should().BeEquivalentTo(s8); u4.Single(x => x.Address.Equals(address4)).Status.Should().Be(MemberStatus.Up); }
public SequenceTokenParser(TEnumerable value) : base(ImmutableSortedSet.Create(new Expected <TToken>(Rope.CreateRange(value)))) { _value = value; _valueTokens = value.ToArray(); }