Skip to content

Instantly share code, notes, and snippets.

@renestein
renestein / GenericNullable1.cs
Last active September 2, 2021 14:22
GenericNullable1.cs
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
MyStack<MyItem> stack = new MyStack<MyItem>();
public class MyStack<T> where T : class
{
private T[] _items;
//Actor inherits from the ActorPolicy class.
class TestActor : public Actors::ActorPolicy
{
public:
TestActor() : ActorPolicy{}
{
}
TEST(SimpleActorTest, WhenUsingAsyncStatefulActorThenHasExpectedState)
{
const int MESSAGES_COUNT = 101;
const int EXPECTED_STATE = MESSAGES_COUNT;
auto seenMessages = 0;
auto testState = 0;
{
//Create the actor (asynchronous logic/with state/no reply).
auto stateFullActor = RStein::AsyncCpp::Actors::CreateAsyncSimpleActor<int, int>([&seenMessages, &testState](const int& message, const int& state)->Task<int>
{
Tasks::Task<size_t> WhenAsyncForkJoinDataflowThenAllInputsProcessedImpl(int inputItemsCount)
{
//Create TransformBlock. As the name of the block suggests, TransformBlock transforms input to output.
//Following block transforms int to string.
auto transform1 = DataFlowAsyncFactory::CreateTransformBlock<int, int>([](const int& item)-> Tasks::Task<int>
{
//Simulate work
co_await Tasks::GetCompletedTask();
auto message = "int: " + to_string(item) + "\n";
cout << message;
#!/bin/bash
ERROR_BACKUP_DIRECTORY_CREATE=80;
ERROR_BACKUP_ERROR=81;
BACKUP_PATH="/mount/OMEGA_1/Public/RPI_BACKUP"
BACKUP_DIR=$(date +"%Y-%m-%d-%HH-%MM")
FULL_BACKUP_FILE_PATH="$BACKUP_PATH$BACKUP_DIR"
oldDir=$(pwd)
[TestMethod]
public virtual async Task Dispose_When_Tasks_Are_Queued_Then_All_Tasks_Are_Executed()
{
const int NUMBER_OF_TASKS = 1000;
const int DELAY_TASK_CAN_CONTINUE_SIGNAL_S = 1;
int numberOfTasksExecuted = 0;
var waitForSignalCts = new CancellationTokenSource();
var tasks = Enumerable.Range(0, NUMBER_OF_TASKS)
[TestMethod]
public async Task WithTaskFactory_When_One_Task_Is_Queued_Then_Task_is_Executed()
{
bool wasTaskExecuted = false;
await TestTaskFactory.StartNew(() => wasTaskExecuted = true);
Assert.IsTrue(wasTaskExecuted);
}
[TestMethod]
[TestMethod]
[ExpectedException(typeof (ArgumentOutOfRangeException))]
public void Ctor_When_Number_Of_Threads_Is_Zero_Then_Throws_ArgumentOutOfRangeException()
{
var threadPool = new IoServiceThreadPoolScheduler(m_ioService, 0);
}
[TestMethod]
[ExpectedException(typeof (ArgumentOutOfRangeException))]
public void Ctor_When_Number_Of_Threads_Is_Negative_Then_Throws_ArgumentOutOfRangeException()
[TestMethod]
[ExpectedException(typeof (ArgumentNullException))]
public void Ctor_When_Io_Service_Is_Null_Then_Throws_ArgumentException()
{
var threadPool = new IoServiceThreadPoolScheduler(null);
}
public abstract class IAutonomousSchedulerTests : ITaskSchedulerTests
{
private TaskFactory m_testTaskFactory;
protected abstract IProxyScheduler ProxyScheduler
{
get;
}
public TaskFactory TestTaskFactory