Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
polomani committed Dec 14, 2023
1 parent 542dd9d commit 37e69dc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 345 deletions.
99 changes: 0 additions & 99 deletions Cognite.Simulator.Extensions/SequencesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,105 +415,6 @@ public static string[] GetStringValues(this SequenceRow row)
}
return result.ToArray();
}

// /// <summary>
// /// Simply upserts a key value pair into a key value pair based sequence
// /// </summary>
// /// <param name="sequences">CDF Sequence resource</param>
// /// <param name="sequenceExternalId">External id of the sequence.</param>
// /// <param name="updateKey">Key in sequence to update</param>
// /// <param name="updateValue">Value to update the Key value pair to</param>
// /// <param name="token">The cancellation token</param>
// /// <returns>Nothing</returns>
// public static async
// Task UpsertItemInKVPSequence(this SequencesResource sequences, string sequenceExternalId, string updateKey, string updateValue, CancellationToken token) {
// if (sequenceExternalId == "") {
// throw new Exception("External Id is required to upsert a sequence");
// }
// SequenceRowQuery query = new SequenceRowQuery();
// query.ExternalId = sequenceExternalId;
// var sequenceList = await sequences.ListRowsAsync(query, token).ConfigureAwait(false);;
// var rows = sequenceList.Rows;
// var columns = sequenceList.Columns;
// var newRows = rows.Select(r => new SequenceRow
// {
// RowNumber = r.RowNumber,
// Values = r.Values
// }).ToList();
// // Checking to see if the key alread exists
// var foundIndex = newRows.FindIndex(0, newRows.Count, (item => item.Values.FirstOrDefault().ToString().Contains(updateKey) ));
// if (foundIndex == -1){
// newRows.Insert(newRows.Count , new SequenceRow{
// RowNumber = newRows.Count,
// Values = new List<MultiValue> {
// MultiValue.Create(updateKey),
// MultiValue.Create(updateValue)
// }
// });
// } else {
// newRows[foundIndex].Values = new List<MultiValue> {
// MultiValue.Create(updateKey),
// MultiValue.Create(updateValue)
// };
// }

// SequenceDataCreate sequenceData = new SequenceDataCreate
// {
// ExternalId = sequenceExternalId,
// Columns = new List<string> {
// KeyValuePairSequenceColumns.Key,
// KeyValuePairSequenceColumns.Value
// },
// Rows = newRows
// };
// var rowsToCreate = new List<SequenceDataCreate>();
// rowsToCreate.Add(sequenceData);
// var result = await sequences.InsertAsync(
// rowsToCreate,
// keyChunkSize: 10,
// valueChunkSize: 100,
// sequencesChunk: 10,
// throttleSize: 1,
// RetryMode.None,
// SanitationMode.None,
// token
// ).ConfigureAwait(false);

// if (!result.IsAllGood)
// {
// throw new SimulatorIntegrationSequenceException("Could not update simulator integration sequence", result.Errors);
// }
// }

// /// <summary>
// /// Gets the externalId of a SimulatorIntegrations sequence (This function can throw an exception)
// /// </summary>
// /// <param name="sequences">CDF Sequence resource</param>
// /// <param name="simulatorName">The simulator name.</param>
// /// <param name="simulatorDataSetId">The simulator datasetId</param>
// /// <param name="connectorName">The connector Name</param>
// /// <param name="token">The cancellation token</param>
// /// <returns>externalId string</returns>
// public static async Task<string> GetSequenceExternalId(this SequencesResource sequences, string simulatorName, long simulatorDataSetId, string connectorName, CancellationToken token) {
// var simulatorSequenceIds = new Dictionary<string, string>();
// var simulatorsDict = new SimulatorIntegration
// {
// Simulator = simulatorName,
// DataSetId = simulatorDataSetId,
// ConnectorName = connectorName
// };

// var integrations = await sequences.GetOrCreateSimulatorIntegrations(
// new List<SimulatorIntegration> { simulatorsDict },
// token).ConfigureAwait(false);
// foreach (var integration in integrations)
// {
// simulatorSequenceIds.Add(
// integration.Metadata[BaseMetadata.SimulatorKey],
// integration.ExternalId);
// }
// return simulatorSequenceIds[simulatorName];
// }
}

/// <summary>
Expand Down
54 changes: 0 additions & 54 deletions Cognite.Simulator.Extensions/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,58 +374,4 @@ public void OverwriteTimeSeriesId(string externalId)
ExternalIdOverwrite = externalId;
}
}

// /// <summary>
// /// Represents simulator integration information in CDF. Each connector can register one or more
// /// simulator integration record with CDF
// /// </summary>
// public class SimulatorIntegration
// {
// /// <summary>
// /// Name of the simulator
// /// </summary>
// public string Simulator { get; set; }

// /// <summary>
// /// Name of the connector
// /// </summary>
// public string ConnectorName { get; set; }

// /// <summary>
// /// ID of the data set that holds simulator data in CDF
// /// </summary>
// public long? DataSetId { get; set; }
// }

// /// <summary>
// /// Represents data used to update the simulator integration information in CDF
// /// </summary>
// public class SimulatorIntegrationUpdate : SimulatorIntegration
// {
// /// <summary>
// /// Version of the connector
// /// </summary>
// public string ConnectorVersion { get; set; }

// /// <summary>
// /// Version of the simulator
// /// </summary>
// public string SimulatorVersion { get; set; }

// /// <summary>
// /// Flag indicating if the connector is using Cognite's Simulator Integration API
// /// or just core CDF resources.
// /// </summary>
// public bool SimulatorApiEnabled { get; set; }

// /// <summary>
// /// Flag indicating if there connector will check for simulator liceses
// /// </summary>
// public bool LicenseCheckEnabled { get; set; }

// /// <summary>
// /// Any extra information that can be registered by the connector
// /// </summary>
// public Dictionary<string, string> ExtraInformation { get; set; } = new Dictionary<string, string>();
// }
}
51 changes: 51 additions & 0 deletions Cognite.Simulator.Tests/TestHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Cognite.Extractor.Common;
using CogniteSdk;
using CogniteSdk.Alpha;

namespace Cognite.Simulator.Tests {
public class TestHelpers {

public static async Task SimulateProsperRunningAsync(Client cdf, string connectorName = "scheduler-test-connector" ) {
var integrations = await cdf.Alpha.Simulators.ListSimulatorIntegrationsAsync(
new SimulatorIntegrationQuery
{
}
).ConfigureAwait(false);
var existing = integrations.Items.FirstOrDefault(i => i.ExternalId == connectorName && i.SimulatorExternalId == "PROSPER");
if (existing == null) {
await cdf.Alpha.Simulators.CreateSimulatorIntegrationAsync(
new List<SimulatorIntegrationCreate>
{
new SimulatorIntegrationCreate
{
ExternalId = connectorName,
SimulatorExternalId = "PROSPER",
DataSetId = CdfTestClient.TestDataset,
Heartbeat = DateTime.UtcNow.ToUnixTimeMilliseconds(),
ConnectorVersion = "N/A",
SimulatorVersion = "N/A",
RunApiEnabled = true,
}
}
).ConfigureAwait(false);
} else {
await cdf.Alpha.Simulators.UpdateSimulatorIntegrationAsync(
new List<SimulatorIntegrationUpdateItem>
{
new SimulatorIntegrationUpdateItem(existing.Id)
{
Update = new SimulatorIntegrationUpdate
{
Heartbeat = new Update<long>(DateTime.UtcNow.ToUnixTimeMilliseconds())
}
}
}
).ConfigureAwait(false);
}
}
}
}
41 changes: 2 additions & 39 deletions Cognite.Simulator.Tests/UtilsTests/SimulationRunnerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task TestSimulationRunnerBase(String calculationName, String calcTy
inTsIds.AddRange(inConstTsIds);
}

await SimulateProsperRunningAsync(cdf, "integration-tests-connector").ConfigureAwait(true);
await TestHelpers.SimulateProsperRunningAsync(cdf, "integration-tests-connector").ConfigureAwait(true);

var runs = await cdf.Alpha.Simulators.CreateSimulationRunsAsync(
new List<SimulationRunCreate>
Expand Down Expand Up @@ -292,44 +292,7 @@ await cdf.TimeSeries.DeleteAsync(new TimeSeriesDelete

}

public static async Task SimulateProsperRunningAsync(Client cdf, string connectorName = "scheduler-test-connector" ) {
var integrations = await cdf.Alpha.Simulators.ListSimulatorIntegrationsAsync(
new SimulatorIntegrationQuery
{
}
).ConfigureAwait(false);
var existing = integrations.Items.FirstOrDefault(i => i.ExternalId == connectorName && i.SimulatorExternalId == "PROSPER");
if (existing == null) {
await cdf.Alpha.Simulators.CreateSimulatorIntegrationAsync(
new List<SimulatorIntegrationCreate>
{
new SimulatorIntegrationCreate
{
ExternalId = connectorName,
SimulatorExternalId = "PROSPER",
DataSetId = CdfTestClient.TestDataset,
Heartbeat = DateTime.UtcNow.ToUnixTimeMilliseconds(),
ConnectorVersion = "N/A",
SimulatorVersion = "N/A",
RunApiEnabled = true,
}
}
).ConfigureAwait(false);
} else {
await cdf.Alpha.Simulators.UpdateSimulatorIntegrationAsync(
new List<SimulatorIntegrationUpdateItem>
{
new SimulatorIntegrationUpdateItem(existing.Id)
{
Update = new SimulatorIntegrationUpdate
{
Heartbeat = new Update<long>(DateTime.UtcNow.ToUnixTimeMilliseconds())
}
}
}
).ConfigureAwait(false);
}
}

private static Dictionary<string, string> ToRowDictionary(SequenceData data)
{
Dictionary<string, string> result = new();
Expand Down
Loading

0 comments on commit 37e69dc

Please sign in to comment.