Execution module solved
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using mROA.Cbor;
|
||||
|
||||
namespace mROA.Test;
|
||||
|
||||
public class CborTest
|
||||
{
|
||||
private ComplexTestObject _complexTestObject;
|
||||
private IContextualSerializationToolKit _serializationToolKit;
|
||||
private BasicCollectionElement _basicCollectionElement;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_basicCollectionElement = new() { A = 567565, B = "test text", C = 2.781f };
|
||||
|
||||
_complexTestObject = new ComplexTestObject
|
||||
{
|
||||
IntValue = 123,
|
||||
DoubleValue = 3.14159,
|
||||
StringValue = "abc",
|
||||
EnumValue = TestEnum.X,
|
||||
CollectionElements =
|
||||
[
|
||||
_basicCollectionElement,
|
||||
new BasicCollectionElement { A = 8_000_000, B = "Fi number", C = 1.618f }
|
||||
],
|
||||
IntArray = [1, 4, 8, 16, 87]
|
||||
};
|
||||
_serializationToolKit = new CborSerializationToolkit();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BasicOnly()
|
||||
{
|
||||
var value = 123;
|
||||
var data = _serializationToolKit.Serialize(value, null);
|
||||
|
||||
var deserialize = _serializationToolKit.Deserialize<int>(data, null);
|
||||
Assert.That(value, Is.EqualTo(deserialize));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComplexFlat()
|
||||
{
|
||||
var value = _basicCollectionElement;
|
||||
var data = _serializationToolKit.Serialize(value, null);
|
||||
var deserialize = _serializationToolKit.Deserialize<BasicCollectionElement>(data, null);
|
||||
Assert.That(value, Is.EqualTo(deserialize));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComplexFull()
|
||||
{
|
||||
var value = _complexTestObject;
|
||||
var data = _serializationToolKit.Serialize(value, null);
|
||||
var deserialize = _serializationToolKit.Deserialize<ComplexTestObject>(data, null);
|
||||
Assert.That(value, Is.EqualTo(deserialize));
|
||||
}
|
||||
|
||||
public void SharedObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private class ComplexTestObject
|
||||
{
|
||||
public int IntValue { get; set; }
|
||||
public double DoubleValue { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
public TestEnum EnumValue { get; set; }
|
||||
public int[] IntArray { get; set; }
|
||||
public List<BasicCollectionElement> CollectionElements { get; set; }
|
||||
|
||||
protected bool Equals(ComplexTestObject other)
|
||||
{
|
||||
return IntValue == other.IntValue && DoubleValue.Equals(other.DoubleValue) && StringValue == other.StringValue && IntArray.SequenceEqual(other.IntArray) && CollectionElements.SequenceEqual(other.CollectionElements);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((ComplexTestObject)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(IntValue, DoubleValue, StringValue, IntArray, CollectionElements);
|
||||
}
|
||||
}
|
||||
|
||||
private class BasicCollectionElement
|
||||
{
|
||||
public int A { get; set; }
|
||||
public string B { get; set; }
|
||||
public float C { get; set; }
|
||||
|
||||
protected bool Equals(BasicCollectionElement other)
|
||||
{
|
||||
return A == other.A && B == other.B && C.Equals(other.C);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((BasicCollectionElement)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(A, B, C);
|
||||
}
|
||||
}
|
||||
|
||||
public enum TestEnum
|
||||
{
|
||||
X = -5, Y, Z
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
// using System.Net;
|
||||
// using System.Net.Sockets;
|
||||
// using System.Reflection;
|
||||
// using mROA.Abstract;
|
||||
// using mROA.Codegen;
|
||||
// using Example.Shared;
|
||||
// using mROA.Implementation;
|
||||
//
|
||||
// namespace mROA.Test;
|
||||
//
|
||||
// public class FrontendFinalTest
|
||||
// {
|
||||
// private StreamBasedInteractionModule _interactionModule;
|
||||
// private StreamBasedFrontendInteractionModule _frontendInteractionModule;
|
||||
// private JsonFrontendSerialisationModule _frontendSerialisationModule;
|
||||
// private ISerialisationModule _serialisationModule;
|
||||
// private IExecuteModule _executeModule;
|
||||
// private IMethodRepository _methodRepository;
|
||||
// private IContextRepository _contextRepository;
|
||||
// bool isTestNotFinished = true;
|
||||
// private IContextRepository _frontendContextRepository;
|
||||
//
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// _methodRepository = new CoCodegenMethodRepository();
|
||||
// var repo2 = new ContextRepository();
|
||||
// repo2.FillSingletons(typeof(ITestController).Assembly);
|
||||
// _contextRepository = repo2;
|
||||
//
|
||||
// _interactionModule = new StreamBasedInteractionModule();
|
||||
//
|
||||
// _serialisationModule = new JsonSerialisationModule();
|
||||
//
|
||||
// _executeModule = new BasicExecutionModule();
|
||||
//
|
||||
// IInjectableModule[] backendModules =
|
||||
// [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule];
|
||||
//
|
||||
// foreach (var backendModule in backendModules)
|
||||
// foreach (var injection in backendModules)
|
||||
// backendModule.Inject(injection);
|
||||
//
|
||||
// _frontendInteractionModule = new StreamBasedFrontendInteractionModule();
|
||||
// _frontendSerialisationModule = new JsonFrontendSerialisationModule();
|
||||
// _frontendContextRepository = new FrontendContextRepository();
|
||||
//
|
||||
// IInjectableModule[] frontendModules =
|
||||
// [_frontendInteractionModule, _frontendSerialisationModule, _frontendContextRepository];
|
||||
//
|
||||
// foreach (var backendModule in frontendModules)
|
||||
// foreach (var injection in frontendModules)
|
||||
// backendModule.Inject(injection);
|
||||
//
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
// TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
|
||||
// listener.Start();
|
||||
//
|
||||
// var stream = listener.AcceptTcpClient().GetStream();
|
||||
//
|
||||
// Console.WriteLine("Client connected");
|
||||
//
|
||||
// _interactionModule.RegisterSourse(stream);
|
||||
//
|
||||
// while (isTestNotFinished) ;
|
||||
// });
|
||||
//
|
||||
// var tcpClient = new TcpClient();
|
||||
// tcpClient.Connect(IPAddress.Loopback, 4567);
|
||||
// _frontendInteractionModule.ServerStream = tcpClient.GetStream();
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void CallTest()
|
||||
// {
|
||||
// var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
|
||||
//
|
||||
// var x = singleton.B();
|
||||
// Console.WriteLine(x);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TransmittionTest()
|
||||
// {
|
||||
// var singleton = _frontendContextRepository.GetSingleObject(typeof(ITestController)) as ITestController;
|
||||
//
|
||||
// var next = singleton.SharedObjectTransmitionTest().Value;
|
||||
// var parameter = singleton.GetTestParameter().Value;
|
||||
// var x = next.Parametrized(new TestParameter { A = 100, LinkedObject = new(parameter!) });
|
||||
// }
|
||||
// }
|
||||
@@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Test
|
||||
{
|
||||
public class NextGenTest
|
||||
{
|
||||
private TcpListener _listener;
|
||||
private ChannelInteractionModule _interactionModuleA;
|
||||
private ChannelInteractionModule _interactionModuleB;
|
||||
private Guid[] guids = [Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()];
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_listener = new TcpListener(IPAddress.Loopback, 4567);
|
||||
_interactionModuleA = new ChannelInteractionModule();
|
||||
_interactionModuleA.Inject(new JsonSerializationToolkit());
|
||||
_interactionModuleB = new ChannelInteractionModule();
|
||||
_interactionModuleB.Inject(new JsonSerializationToolkit());
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultithreadedTest()
|
||||
{
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
_listener.Start();
|
||||
// _interactionModuleB.BaseStream = _listener.AcceptTcpClient().GetStream();
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
_interactionModuleB.PostMessageAsync(new NetworkMessageHeader { Id = guid, Data = "Hello user"u8.ToArray() });
|
||||
}
|
||||
});
|
||||
|
||||
var client = new TcpClient();
|
||||
client.Connect(IPAddress.Loopback, 4567);
|
||||
// _interactionModuleA.BaseStream = client.GetStream();
|
||||
|
||||
var tasks = guids.Select(ReadStream);
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
Assert.Pass();
|
||||
|
||||
}
|
||||
|
||||
private async Task ReadStream(Guid current)
|
||||
{
|
||||
var msg = await _interactionModuleA.GetNextMessageReceiving();
|
||||
Console.WriteLine(
|
||||
$"{Environment.CurrentManagedThreadId} Received message: {Encoding.Default.GetString(new JsonSerializationToolkit().Serialize(msg))}");
|
||||
while (msg.Id != current)
|
||||
{
|
||||
msg = await _interactionModuleA.GetNextMessageReceiving();
|
||||
Console.WriteLine(
|
||||
$"{Environment.CurrentManagedThreadId} Received message: {Encoding.Default.GetString(new JsonSerializationToolkit().Serialize(msg))}");
|
||||
}
|
||||
|
||||
Console.WriteLine($"{Environment.CurrentManagedThreadId} Good message received");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_listener.Stop();
|
||||
_listener.Dispose();
|
||||
_interactionModuleA.Dispose();
|
||||
_interactionModuleB.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// using System.Net;
|
||||
// using System.Net.Sockets;
|
||||
// using System.Text.Json;
|
||||
// using mROA.Implementation;
|
||||
//
|
||||
// namespace mROA.Test;
|
||||
//
|
||||
// public class StreamTest
|
||||
// {
|
||||
// private StreamBasedInteractionModule _interactionModule;
|
||||
// private StreamBasedFrontendInteractionModule _frontendInteractionModule;
|
||||
// private JsonFrontendSerialisationModule _frontendSerialisationModule;
|
||||
// private ISerialisationModule _serialisationModule;
|
||||
// private IExecuteModule _executeModule;
|
||||
// bool isTestNotFinished = true;
|
||||
//
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// _interactionModule = new StreamBasedInteractionModule();
|
||||
//
|
||||
// _serialisationModule = new JsonSerialisationModule(_interactionModule, new MockMethodRepository());
|
||||
//
|
||||
// _executeModule = new MockExecModule();
|
||||
// _serialisationModule.SetExecuteModule(_executeModule);
|
||||
//
|
||||
// _frontendInteractionModule = new StreamBasedFrontendInteractionModule();
|
||||
// _frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
|
||||
//
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
// TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
|
||||
// listener.Start();
|
||||
//
|
||||
// var stream = listener.AcceptTcpClient().GetStream();
|
||||
//
|
||||
// Console.WriteLine("Client connected");
|
||||
//
|
||||
// _interactionModule.RegisterSourse(stream);
|
||||
//
|
||||
// while (isTestNotFinished) ;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void StreamingTest()
|
||||
// {
|
||||
// var tcpClient = new TcpClient();
|
||||
// tcpClient.Connect(IPAddress.Loopback, 4567);
|
||||
// _frontendInteractionModule.ServerStream = tcpClient.GetStream();
|
||||
//
|
||||
// var req = new DefaultCallRequest { CommandId = 1, ObjectId = -1 };
|
||||
// _frontendSerialisationModule.PostCallRequest(req);
|
||||
// var res = ((JsonElement)_frontendSerialisationModule
|
||||
// .GetNextCommandExecution<FinalCommandExecution>(req.CallRequestId).GetAwaiter().GetResult().Result!)
|
||||
// .Deserialize<MockResult>();
|
||||
// isTestNotFinished = false;
|
||||
// Assert.That(res.A == "wqer" && res.B == 5);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void RemoteObjectTest()
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
@@ -1,26 +0,0 @@
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Test;
|
||||
|
||||
public class UnSOization
|
||||
{
|
||||
private ComplexObjectIdentifier _uoi;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_uoi = new ComplexObjectIdentifier
|
||||
{
|
||||
ContextId = -123, OwnerId = 123
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FlatTest()
|
||||
{
|
||||
var flat = _uoi.Flat;
|
||||
var next = new ComplexObjectIdentifier { Flat = flat };
|
||||
|
||||
Assert.That(_uoi, Is.EqualTo(next));
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
// using System.Diagnostics;
|
||||
// using System.Reflection;
|
||||
// using System.Text;
|
||||
// using System.Text.Json;
|
||||
// using Example.Shared;
|
||||
// using mROA.Implementation;
|
||||
// using Newtonsoft.Json;
|
||||
// using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
//
|
||||
// namespace mROA.Test;
|
||||
//
|
||||
// public class Tests
|
||||
// {
|
||||
// private ProgramlyInteractionChanel _interactionModule;
|
||||
// private ISerialisationModule _serialisationModule;
|
||||
// private IExecuteModule _executeModule;
|
||||
// private IMethodRepository _methodRepository;
|
||||
// private IContextRepository _contextRepository;
|
||||
//
|
||||
// private ITestController _testController;
|
||||
//
|
||||
// [SetUp]
|
||||
// public void Setup()
|
||||
// {
|
||||
// _interactionModule = new ProgramlyInteractionChanel();
|
||||
// var repo = new MethodRepository();
|
||||
// repo.CollectForAssembly(Assembly.GetExecutingAssembly());
|
||||
// _methodRepository = repo;
|
||||
// var repo2 = new ContextRepository();
|
||||
// repo2.FillSingletons(Assembly.GetExecutingAssembly());
|
||||
// _contextRepository = repo2;
|
||||
// _serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
|
||||
//
|
||||
// _executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
|
||||
// TransmissionConfig.DefaultContextRepository = _contextRepository;
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void CommandPipelineTest()
|
||||
// {
|
||||
// var sw = Stopwatch.StartNew();
|
||||
//
|
||||
// _interactionModule.PassCommand(132, """
|
||||
// {
|
||||
// "RequestTypeId": 0,
|
||||
// "CommandId": 2
|
||||
// }
|
||||
// """u8.ToArray());
|
||||
// Assert.Pass(_interactionModule.OutputBuffer.Last());
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void CommandPipelineTestAsync()
|
||||
// {
|
||||
// var sw = Stopwatch.StartNew();
|
||||
// _interactionModule.PassCommand(132, """
|
||||
// {
|
||||
// "RequestTypeId": 0,
|
||||
// "CommandId": 3
|
||||
// }
|
||||
// """u8.ToArray());
|
||||
// while (_interactionModule.OutputBuffer.Count != 2) ;
|
||||
//
|
||||
// Assert.Pass(_interactionModule.OutputBuffer.Last());
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void MethodRegistrationTest()
|
||||
// {
|
||||
// var repo = new MethodRepository();
|
||||
// repo.CollectForAssembly(Assembly.GetExecutingAssembly());
|
||||
// Assert.That(repo.GetMethods().ToList().Count == 8);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void ContextSupplyTest()
|
||||
// {
|
||||
// var repo = new ContextRepository();
|
||||
// repo.FillSingletons(Assembly.GetExecutingAssembly());
|
||||
// var singleObject = repo.GetSingleObject(typeof(ITestController)) as ITestController;
|
||||
// singleObject.B();
|
||||
// Assert.That(singleObject.B() == 6);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TransmissionTest()
|
||||
// {
|
||||
// _interactionModule.PassCommand(132, """
|
||||
// {
|
||||
// "CommandId": 4
|
||||
// }
|
||||
// """u8.ToArray());
|
||||
// var response =
|
||||
// JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
||||
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
||||
// ?.Result.ToString()
|
||||
// );
|
||||
//
|
||||
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||
//
|
||||
// var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
||||
// .GetInt32();
|
||||
//
|
||||
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 4, ObjectId = response.ContextId })));
|
||||
//
|
||||
// response =
|
||||
// JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
|
||||
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
||||
// ?.Result.ToString()
|
||||
// );
|
||||
//
|
||||
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
|
||||
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
|
||||
//
|
||||
// var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
|
||||
// .GetInt32();
|
||||
//
|
||||
// Assert.That(firstFull == 456789 && secondFull == 6);
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void LinkedObjectsAndParametersTest()
|
||||
// {
|
||||
// _interactionModule.PassCommand(132, """
|
||||
// {
|
||||
// "CommandId": 6
|
||||
// }
|
||||
// """u8.ToArray());
|
||||
// var response =
|
||||
// JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
|
||||
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
|
||||
// ?.Result.ToString()
|
||||
// );
|
||||
// var x = response.ContextId;
|
||||
// _interactionModule.PassCommand(132,Encoding.UTF8.GetBytes(
|
||||
// JsonSerializer.Serialize(new DefaultCallRequest
|
||||
// {
|
||||
// CommandId = 5,
|
||||
// Parameter = new TestParameter
|
||||
// {
|
||||
// A = 10,
|
||||
// LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
|
||||
// }
|
||||
// })));
|
||||
//
|
||||
// var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
|
||||
//
|
||||
// Assert.That(finalResponse, Is.EqualTo(20));
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user