public void CommandBatch_Execute_Success() { // Arrange Command.Counter = 0; var command1 = new Command(2); var command2 = new Command(1); var command3 = new Command(3); // Act var batch = new CommandBatch(); batch.Add(command3) .Add(command2) .Add(command1) .Execute(); var task = Task.Run(async() => { while (batch.IsDone == false) { await Task.Delay(TimeSpan.FromMilliseconds(20)); } return(1); }); var unused = task.Result; //Assert Assert.AreEqual(1, command2.Count); Assert.AreEqual(2, command1.Count); Assert.AreEqual(3, command3.Count); }
// public override void SendBatch(CommandBatch commandBatch) { // Extract serialisation from cache CommandHttpClientCache serialisedCache = (CommandHttpClientCache)commandBatch.SerialisedCache; string batchUrl = serialisedCache.BatchUrl; string postData = serialisedCache.PostData; Dictionary <string, string> headers = serialisedCache.Headers; // Send HTTP request SendRequest(batchUrl, postData, headers, responseArray => { // Process each command response try { for (var batchId = 0; batchId < responseArray.Count; batchId += 1) { var commandResponse = responseArray[batchId] as JArray; if (commandResponse == null) { throw new Exception("Response item " + batchId + " is not an Array:" + responseArray); } CommandBatchItem commandItem = commandBatch.BatchItems[batchId]; string commandName = commandItem.CommandName; Action <Exception, JToken> commandCb = commandItem.Cb; // Check if there are any events attached to this request if (commandResponse.Count >= 3) { Logger.Verbose("[" + commandName + "] processing events"); Mage.EventManager.EmitEventList((JArray)commandResponse[2]); } // Check if the response was an error if (commandResponse[0].Type != JTokenType.Null) { Logger.Verbose("[" + commandName + "] server error"); commandCb(new Exception(commandResponse[0].ToString()), null); continue; } // Pull off call result object, if it doesn't exist Logger.Verbose("[" + commandName + "] call response"); try { commandCb(null, commandResponse[1]); } catch (Exception error) { Logger.Data(error).Error("Error during command callback"); } } } catch (Exception error) { Logger.Data(error).Error("Error when processing command batch responses"); } }); }
public void ShouldAddACommandToTheCommandBatch(Type fixtureType) { var fixture = Activator.CreateInstance(fixtureType) as CommandBatchFixtureBase; var commandBatch = new CommandBatch(fixture.Connector); var commandBuilderFactory = fixture.Connector.GetCommandBuilderFactory(); var tableTypeDescriptor = DescriptorCache.Instance.GetTableTypeDescriptor(typeof(BatchMock)); var valueProvider = new ClassValueProvider(fixture.Connector, new List <object> { fixture.CreateMock(), fixture.CreateMock() }); commandBatch.Add(new CommandBatchStep(commandBuilderFactory.CreateInsertCommandBuilder(tableTypeDescriptor).GetCommand(valueProvider))); commandBatch.Add(new CommandBatchStep(commandBuilderFactory.CreateInsertCommandBuilder(tableTypeDescriptor).GetCommand(valueProvider))); commandBatch.GetCommand().CommandText.Should().Be(fixture.CommandBatchText); }
public ComposerBatch( CommandSequence root, IModesController modesController, Composer composer) { Requires.NotNull(root, nameof(root)); Requires.NotNull(modesController, nameof(modesController)); Requires.NotNull(composer, nameof(composer)); this.root = root; this.modesController = modesController; this.composer = composer; batch = new CommandBatch(); root.Add(batch); }
// public override void SerialiseBatch(CommandBatch commandBatch) { Logger.Verbose("THIS TRANSPORT CLIENT IS NOT IMPLEMENTED"); throw new Exception("THIS TRANSPORT CLIENT IS NOT IMPLEMENTED"); }
public abstract void SendBatch(CommandBatch batch);
public abstract void SerialiseBatch(CommandBatch commandBatch);