public AccessSafely AfterCompleting(int times) { Access = AccessSafely .AfterCompleting(times) .WritingWith("informedCount", (int increment) => InformedCount.Set(InformedCount.Get() + increment)) .ReadingWith("informedCount", () => InformedCount.Get()); return(Access); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely.AfterCompleting(times) .WritingWith <JournalData <TEntry, TState> >("appendResultedIn", j => _entries.Add(j)) .ReadingWith("appendResultedIn", () => _entries) .ReadingWith("size", () => _entries.Count); return(_access); }
private AccessSafely AfterCompleting(int steps) { Access = AccessSafely .AfterCompleting(steps) .WritingWith <int>("answers", answer => answers[index++] = answer) .ReadingWith <int, int>("answers", indx => answers[indx]); return(Access); }
public TestResults(int times) { var invoked = new AtomicBoolean(false); _safely = AccessSafely .AfterCompleting(times) .WritingWith <bool>("invoked", val => invoked.Set(val)) .ReadingWith("invoked", invoked.Get); }
public CounterHolder(int times) { var counter = new AtomicInteger(0); _safely = AccessSafely .AfterCompleting(times) .WritingWith <int>("counter", _ => counter.IncrementAndGet()) .ReadingWith("counter", counter.Get); }
public AccessSafely TerminatingStopCountAccessCompletes(int times) { TerminatingStopCountAccess = AccessSafely .AfterCompleting(times) .WritingWith("value", (int value) => TerminatingStopCount.Set(TerminatingStopCount.Get() + value)) .ReadingWith("value", () => TerminatingStopCount.Get()); return(TerminatingStopCountAccess); }
public AccessSafely TerminatingAccessCompletes(int times) { TerminatingAccess = AccessSafely .AfterCompleting(times) .WritingWith("value", (bool flag) => Terminating.Set(flag)) .ReadingWith("value", () => Terminating.Get()); return(TerminatingAccess); }
public AccessSafely BeforeStartCountAccessCompletes(int times) { BeforeStartCountAccess = AccessSafely .AfterCompleting(times) .WritingWith("value", (int value) => BeforeStartCount.Set(BeforeStartCount.Get() + value)) .ReadingWith("value", () => BeforeStartCount.Get()); return(BeforeStartCountAccess); }
public MockResponseSenderChannel() { AbandonCount = new AtomicInteger(0); EventsResponse = new AtomicReference <Response>(); RespondWithCount = new AtomicInteger(0); Response = new AtomicReference <Response>(); _abandonSafely = ExpectAbandon(0); _respondWithSafely = ExpectRespondWith(0); _receivedStatus = false; }
internal AccessSafely AfterCompleting(int times) { _access = AccessSafely.AfterCompleting(times) .WritingWith <List <BaseEntry <string> > >("addAll", values => Entries.AddRange(values)) .ReadingWith <int, BaseEntry <string> >("entry", index => Entries[index]) .ReadingWith <int, string>("entryId", index => Entries[index].Id) .ReadingWith("size", () => Entries.Count); return(_access); }
public TestResults(int times) { var invoices = new ConcurrentDictionary <ERPSystemCode, IList <Invoice> >(); submittedInvoices = AccessSafely.AfterCompleting(times); submittedInvoices.WritingWith <ERPSystemCode, Invoice>( "submittedInvoices", (key, value) => invoices.GetOrAdd(key, new List <Invoice>()).Add(value)); submittedInvoices.ReadingWith <ERPSystemCode, IList <Invoice> >("submittedInvoices", key => invoices.GetValueOrDefault(key)); }
public TestResults(int happenings) { var highest = new AtomicInteger(0); safely = AccessSafely .AfterCompleting(happenings) .WritingWith <int>("highest", x => highest.Set(x)) .ReadingWith("highest", highest.Get) .ReadingWith <int, bool>("isHighest", count => count > highest.Get()); }
public static TestResults AfterCompleting(int times) { var testResults = new TestResults(AccessSafely.AfterCompleting(times)); testResults.received.WritingWith <bool>("receivedBeforeStart", testResults.receivedBeforeStart.Set); testResults.received.ReadingWith("receivedBeforeStart", testResults.receivedBeforeStart.Get); testResults.received.WritingWith <bool>("receivedAfterStop", testResults.receivedAfterStop.Set); testResults.received.ReadingWith("receivedAfterStop", testResults.receivedAfterStop.Get); return(testResults); }
private AccessSafely(AccessSafely existing, int happenings) { _totalWrites = existing._totalWrites; _until = TestUntil.Happenings(happenings); _biConsumers = existing._biConsumers; _consumers = existing._consumers; _functions = existing._functions; _suppliers = existing._suppliers; _lock = new object(); }
public AccessSafely AfterCompleting(int times) { Access = AccessSafely .AfterCompleting(times) .WritingWith("pongCount", (int increment) => PongCount.Set(PongCount.Get() + increment)) .ReadingWith("pongCount", () => PongCount.Get()) .WritingWith("stopCount", (int increment) => StopCount.Set(StopCount.Get() + increment)) .ReadingWith("stopCount", () => StopCount.Get()); return(Access); }
public AccessSafely AfterCompleting(int times) { ScanFound = AccessSafely .AfterCompleting(times) .WritingWith("foundCount", (int increment) => foundCount.Set(foundCount.Get() + increment)) .ReadingWith("foundCount", () => foundCount.Get()) .WritingWith("notFoundCount", (int increment) => notFoundCount.Set(notFoundCount.Get() + increment)) .ReadingWith("notFoundCount", () => notFoundCount.Get()); return(ScanFound); }
public static TestResults AfterCompleting(int times) { var testResults = new TestResults(AccessSafely.AfterCompleting(times)); testResults.received.WritingWith <string>("receivedGreeting", s => testResults.receivedGreeting.Set(s)); testResults.received.ReadingWith("receivedGreeting", testResults.receivedGreeting.Get); testResults.received.WritingWith <int>("receivedValue", v => testResults.receivedValue.Set(v)); testResults.received.ReadingWith("receivedValue", testResults.receivedValue.Get); testResults.received.WritingWith <bool>("exceptionThrown", e => testResults.exceptionThrown.Set(e)); testResults.received.ReadingWith("exceptionThrown", testResults.exceptionThrown.Get); return(testResults); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely .AfterCompleting(times) .WritingWith <object>("add", value => _stateObjects.Add(value)) .WritingWith <object>("addAll", values => _stateObjects.AddRange((List <StateObject>)values)) .ReadingWith <int, object>("object", index => _stateObjects[index]) .ReadingWith("size", () => _stateObjects.Count); return(_access); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely.AfterCompleting(times) .WritingWith <Dispatchable <TEntry, TState> >("dispatched", action => _dispatched.Add(action)) .ReadingWith("dispatched", () => _dispatched) .WritingWith <bool>("processDispatch", s => _processDispatch.Set(s)) .ReadingWith("processDispatch", () => _processDispatch.Get()) .ReadingWith("dispatchAttemptCount", () => _dispatchAttemptCount); return(_access); }
public MockCompletes(int times) : base((Scheduler)null) { _safely = AccessSafely.AfterCompleting(times) .WritingWith <T>("outcome", val => { _outcome.Set(val); _withCount.IncrementAndGet(); }) .ReadingWith("outcome", _outcome.Get) .ReadingWith("count", _withCount.Get); }
/// <summary> /// Answer with an AccessSafely which writes responses to "consume" and reads the write count from "completed". /// </summary> /// <param name="n">Number of times consume(response) must be called before readFrom(...) will return.</param> /// <returns>AccessSafely</returns> /// <remarks>Clients can replace the default lambdas with their own via readingWith/writingWith.</remarks> public AccessSafely ExpectConsumeTimes(int n) { ConsumeCalls = AccessSafely.AfterCompleting(n); ConsumeCalls.WritingWith <Response>("consume", response => { Responses.Enqueue(response); ConsumeCount.IncrementAndGet(); }) .ReadingWith("completed", () => ConsumeCalls.TotalWrites); return(ConsumeCalls); }
public ScanResult(int times) { var foundCount = new AtomicInteger(0); var notFoundCount = new AtomicInteger(0); safely = AccessSafely .AfterCompleting(times) .WritingWith <int>("foundCount", _ => foundCount.IncrementAndGet()) .ReadingWith("foundCount", foundCount.Get) .WritingWith <int>("notFoundCount", _ => notFoundCount.IncrementAndGet()) .ReadingWith("notFoundCount", notFoundCount.Get); }
public void TestPublisherChannelReaderWithMultipleClients() { var publisherCount = 0; var accessSafely = AccessSafely.AfterCompleting(4) .WritingWith <int>("publisherCount", (value) => publisherCount += value) .ReadingWith("publisherCount", () => publisherCount); var publisherConsumer = new MockChannelReaderConsumer("publisherCount"); publisherConsumer.UntilConsume = accessSafely; var publisher = new MulticastPublisherReader( "test-publisher", new Group("237.37.37.2", 37391), 37399, 1024, publisherConsumer, ConsoleLogger.TestInstance()); var client1 = new SocketChannelWriter( Address.From( Host.Of("localhost"), 37399, AddressType.Main), ConsoleLogger.TestInstance()); var client2 = new SocketChannelWriter( Address.From( Host.Of("localhost"), 37399, AddressType.Main), ConsoleLogger.TestInstance()); var client3 = new SocketChannelWriter( Address.From( Host.Of("localhost"), 37399, AddressType.Main), ConsoleLogger.TestInstance()); client1.Write(RawMessage.From(1, 1, "test-response1"), new MemoryStream()); client2.Write(RawMessage.From(1, 1, "test-response2"), new MemoryStream()); client3.Write(RawMessage.From(1, 1, "test-response3"), new MemoryStream()); client1.Write(RawMessage.From(1, 1, "test-response1"), new MemoryStream()); publisher.ProbeChannel(); publisher.ProbeChannel(); publisher.ProbeChannel(); publisher.ProbeChannel(); Assert.Equal(4, publisherCount); }
public void TestThatActorAnswersEventually() { var access = AccessSafely.AfterCompleting(1); access.WritingWith <int>("answer", answer => _value.Set(answer)); access.ReadingWith("answer", () => _value.Get()); _answerGiver.Calculate("10", 5).AndThenConsume(answer => access.WriteUsing("answer", answer)); var answer = access.ReadFrom <int>("answer"); Assert.Equal(50, answer); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely .AfterCompleting(times) .WritingWith("appended", (IEntry appended) => _entries.Add(appended)) .WritingWith("appendedAll", (List <IEntry> appended) => _entries.AddRange(appended)) .ReadingWith <int, IEntry>("appendedAt", index => _entries[index]) .ReadingWith("entries", () => _entries) .ReadingWith("entriesCount", () => _entries.Count); return(_access); }
public void TestMulticastPublishSubscribe() { var publisherCount = 0; var subscriberCount = 0; var accessSafely = AccessSafely.Immediately() .WritingWith <int>("publisherCount", (value) => publisherCount += value) .ReadingWith("publisherCount", () => publisherCount) .WritingWith <int>("subscriberCount", (value) => subscriberCount += value) .ReadingWith("subscriberCount", () => subscriberCount); var publisherConsumer = new MockChannelReaderConsumer("publisherCount"); publisherConsumer.UntilConsume = accessSafely; var publisher = new MulticastPublisherReader( "test-publisher", new Group("237.37.37.1", 37771), 37779, 1024, publisherConsumer, ConsoleLogger.TestInstance()); var subscriber = new MulticastSubscriber( "test-subscriber", new Group("237.37.37.1", 37771), 1024, 10, ConsoleLogger.TestInstance()); var subscriberConsumer = new MockChannelReaderConsumer("subscriberCount"); subscriberConsumer.UntilConsume = accessSafely; subscriber.OpenFor(subscriberConsumer); for (int idx = 0; idx < 10; ++idx) { publisher.SendAvailability(); } publisher.ProcessChannel(); for (int i = 0; i < 2; ++i) { subscriber.ProbeChannel(); } subscriberConsumer.UntilConsume.ReadFromExpecting("subscriberCount", 10); Assert.Equal(0, publisherCount); Assert.Equal(10, subscriberCount); }
public void TestGappyRequestResponse() { _output.WriteLine("Starting TestGappyRequestResponse"); var requestPart1 = "Request Part-1"; var requestPart2 = "Request Part-2"; var requestPart3 = "Request Part-3"; _serverConsumer.CurrentExpectedRequestLength = requestPart1.Length + requestPart2.Length + requestPart3.Length; _clientConsumer.CurrentExpectedResponseLength = _serverConsumer.CurrentExpectedRequestLength; var serverConsumeCount = 0; var clientConsumeCount = 0; var accessSafely = AccessSafely.AfterCompleting(1) .WritingWith <int>("serverConsume", (value) => serverConsumeCount += value) .ReadingWith("serverConsume", () => serverConsumeCount) .WritingWith <int>("clientConsume", (value) => clientConsumeCount += value) .ReadingWith("clientConsume", () => clientConsumeCount); _serverConsumer.UntilConsume = accessSafely; _clientConsumer.UntilConsume = accessSafely; // simulate network latency for parts of single request Request(requestPart1); Thread.Sleep(100); Request(requestPart2); Thread.Sleep(200); Request(requestPart3); while (_serverConsumer.UntilConsume.ReadFrom <int>("serverConsume") < 1) { ; } _serverConsumer.UntilConsume.ReadFromExpecting("serverConsume", 1); while (_clientConsumer.UntilConsume.ReadFrom <int>("clientConsume") < 1) { _client.ProbeChannel(); } _clientConsumer.UntilConsume.ReadFromExpecting("clientConsume", 1); Assert.Equal(1, _serverConsumer.UntilConsume.ReadFrom <int>("serverConsume")); Assert.Equal(1, serverConsumeCount); Assert.Equal(serverConsumeCount, _serverConsumer.Requests.Count); Assert.Equal(1, _clientConsumer.UntilConsume.ReadFrom <int>("clientConsume")); Assert.Equal(1, clientConsumeCount); Assert.Equal(clientConsumeCount, _clientConsumer.Responses.Count); Assert.Equal(_clientConsumer.Responses[0], _serverConsumer.Requests[0]); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely.AfterCompleting(times); _access.WritingWith <string>("responses", (response) => { _responses.Add(response); ConsumeCount.IncrementAndGet(); }); _access.ReadingWith <IEnumerable <string> >("responses", () => _responses); _access.ReadingWith("consumeCount", () => ConsumeCount.Get()); return(_access); }
public AccessSafely AfterCompleting(int times) { _access = AccessSafely.AfterCompleting(times); _access .WritingWith <LocalType1>("addMessage", message => _results.Enqueue(message)) .ReadingWith("getMessage", () => { if (_results.TryDequeue(out var localType)) { return((LocalType1)localType); } return(null); });
public MessageCountingResults(int times) { _access = AccessSafely.AfterCompleting(times); _access.WritingWith("ctor", (InstantiationType type) => { _ctor.IncrementAndGet(); if (type == InstantiationType.Reader) { _readerCtor.IncrementAndGet(); } else if (type == InstantiationType.Writer) { _writerCtor.IncrementAndGet(); } }); _access.ReadingWith("ctor", () => _ctor.Get()); _access.ReadingWith("readerCtor", () => _readerCtor.Get()); _access.ReadingWith("writerCtor", () => _writerCtor.Get()); _access.WritingWith("read", (string id, int totalPartitions) => { _read.IncrementAndGet(); var partition = PartitioningStateStore.PartitionOf(id, totalPartitions); _readPartitions.TryGetValue(partition, out var count); _readPartitions.AddOrUpdate(partition, i => 1, (x, y) => count + 1); }); _access.ReadingWith("read", () => _read.Get()); _access.WritingWith <int>("readAll", one => _readAll.IncrementAndGet()); _access.ReadingWith("readAll", () => _readAll.Get()); _access.WritingWith <int>("streamAllOf", one => _streamAllOf.IncrementAndGet()); _access.ReadingWith("streamAllOf", () => _streamAllOf.Get()); _access.WritingWith <int>("streamSomeUsing", one => _streamSomeUsing.IncrementAndGet()); _access.ReadingWith("streamSomeUsing", () => _streamSomeUsing.Get()); _access.WritingWith("write", (string id, int totalPartitions) => { _write.IncrementAndGet(); var partition = PartitioningStateStore.PartitionOf(id, totalPartitions); _writePartitions.TryGetValue(partition, out var count); _writePartitions.AddOrUpdate(partition, i => 1, (x, y) => count + 1); }); _access.ReadingWith("write", () => _write.Get()); _access.WritingWith <int>("entryReader", one => _entryReader.IncrementAndGet()); _access.ReadingWith("entryReader", () => _entryReader.Get()); }