private void DoReadCommand(ReadCommand command, IConnectionManager connection) { List <Task <DataTable> > tasks = new List <Task <DataTable> >(); foreach (string podName in workers) { tasks.Add(RelayReadCommand(podName, command, connection)); } List <DataTable> tables = new List <DataTable>(); foreach (Task <DataTable> task in tasks) { task.Wait(); if (task.Status == TaskStatus.Faulted || task.Exception != null) { throw new Exception($"{command} failed", task.Exception); } if (task.Result != null) { tables.Add(task.Result); } } command.Result = DataTableUtilities.Merge(tables); foreach (string param in command.Parameters) { if (command.Result.Columns[param] == null) { throw new Exception($"Column {param} does not exist in table {command.TableName} (it appears to have disappeared in the merge)"); } } }
public void TestMergeNothing() { DataTable result = DataTableUtilities.Merge(Enumerable.Empty <DataTable>()); Assert.AreEqual("", result.TableName); Assert.AreEqual(0, result.Rows.Count); Assert.AreEqual(0, result.Columns.Count); }
private void DoReadCommand(ReadCommand command, IConnectionManager connection) { List <DataTable> tables = new List <DataTable>(); foreach (string podName in workers) { V1Pod pod = GetWorkerPod(podName); if (string.IsNullOrEmpty(pod.Status.PodIP)) { throw new NotImplementedException("Pod IP not set."); } // Create a new socket connection to the pod. string ip = pod.Status.PodIP; WriteToLog($"Attempting connection to pod {podName} on {ip}:{portNo}"); using (NetworkSocketClient conn = new NetworkSocketClient(relayOptions.Verbose, ip, portNo, Protocol.Managed)) { WriteToLog($"Connection to {podName} established. Sending command..."); // Relay the command to the pod. try { tables.Add(conn.ReadOutput(command)); } catch (Exception err) { WriteToLog($"Unable to read output from pod {podName}:"); WriteToLog(err.ToString()); } WriteToLog($"Closing connection to {podName}..."); } } WriteToLog($"Merging {tables.Count} DataTables (from {workers.Count()} pods)..."); command.Result = DataTableUtilities.Merge(tables); connection.OnCommandFinished(command); }
/// <summary> /// Merge a collection of tables and ensure that the resultant table /// contains all rows from all of the tables. /// </summary> /// <param name="tables">Tables to be merged.</param> private void TestMerge(params DataTable[] tables) { // Merge the tables. DataTable merged = DataTableUtilities.Merge(tables); // Ensure that merge worked correctly. string expectedName = tables.FirstOrDefault()?.TableName ?? ""; Assert.AreEqual(expectedName, merged.TableName); int i = 0; foreach (DataTable table in tables) { foreach (DataRow row in table.Rows) { for (int j = 0; j < table.Columns.Count; j++) { Assert.AreEqual(row[j], merged.Rows[i][j]); } i++; } } }
public void TestMergeNull() { Assert.AreEqual(null, DataTableUtilities.Merge(null)); }