Esempio n. 1
0
        public static async Task Main(string[] args)
        {
            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                // Register your workflow and activity implementations to let
                // Cadence know we're open for business.

                await client.RegisterAssemblyAsync(System.Reflection.Assembly.GetExecutingAssembly());

                await client.StartWorkerAsync("my-tasks");

                // Invoke the workflow.

                var workflowStub = client.NewWorkflowStub <IEmailWorkflow>();

                await workflowStub.SendMessagesAsync();
            }
        }
Esempio n. 2
0
        public Test_SignalChecks(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            if (fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };
            }
            else
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };
            }
        }
Esempio n. 3
0
        public static async Task Main(string[] args)
        {
            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                // Register your workflow implementation to let Cadence
                // know we're open for business.

                await client.RegisterWorkflowAsync <HelloWorkflow>();

                await client.StartWorkerAsync("my-tasks");

                // Invoke your workflow.

                var stub = client.NewWorkflowStub <IHelloWorkflow>();

                Console.WriteLine(await stub.HelloAsync("Jeff"));
            }
        }
Esempio n. 4
0
        public static async Task Main(string[] args)
        {
            try
            {
                var settings = new CadenceSettings("cadence://localhost:7933")
                {
                    DefaultDomain = "test-domain",
                    CreateDomain  = true
                };

                using (var client = await CadenceClient.ConnectAsync(settings))
                {
                    await client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly());

                    await client.StartWorkerAsync(taskList : "hello-tasks");

                    var stub   = client.NewWorkflowStub <IHelloWorkflow>();
                    var result = await stub.HelloAsync("Sally");

                    Console.WriteLine($"RESULT: {result}");
                }
            }
            catch (ConnectException)
            {
                Console.Error.WriteLine("Cannot connect to Cadence.  Be sure you've started a");
                Console.Error.WriteLine("local Cadence Docker container via:");
                Console.Error.WriteLine();
                Console.Error.WriteLine("docker run --detach --name cadence-dev -p 7933-7939:7933-7939 -p 8088:8088 nkubeio/cadence-dev");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// <para>
        /// Starts a Cadence container if it's not already running.  You'll generally want
        /// to call this in your test class constructor instead of <see cref="ITestFixture.Start(Action)"/>.
        /// </para>
        /// <note>
        /// You'll need to call <see cref="StartAsComposed(CadenceSettings, string, string, string[], string, LogLevel, bool, bool, string, bool, bool, bool)"/>
        /// instead when this fixture is being added to a <see cref="ComposedFixture"/>.
        /// </note>
        /// </summary>
        /// <param name="settings">Optional Cadence settings.</param>
        /// <param name="image">Optionally specifies the Cadence container image (defaults to <b>nkubeio/cadence-dev:latest</b>).</param>
        /// <param name="name">Optionally specifies the Cadence container name (defaults to <c>cadence-dev</c>).</param>
        /// <param name="env">Optional environment variables to be passed to the Cadence container, formatted as <b>NAME=VALUE</b> or just <b>NAME</b>.</param>
        /// <param name="defaultDomain">Optionally specifies the default domain for the fixture's client.  This defaults to <b>test-domain</b>.</param>
        /// <param name="logLevel">Specifies the Cadence log level.  This defaults to <see cref="LogLevel.None"/>.</param>
        /// <param name="keepConnection">
        /// Optionally specifies that a new Cadence connection <b>should not</b> be established for each
        /// unit test case.  The same connection will be reused which will save about a second per test.
        /// </param>
        /// <param name="keepOpen">
        /// Optionally indicates that the container should continue to run after the fixture is disposed.
        /// </param>
        /// <param name="hostInterface">
        /// Optionally specifies the host interface where the container public ports will be
        /// published.  This defaults to <see cref="ContainerFixture.DefaultHostInterface"/>
        /// but may be customized.  This needs to be an IPv4 address.
        /// </param>
        /// <param name="noClient">
        /// Optionally disables establishing a client connection when <c>true</c>
        /// is passed.  The <see cref="Client"/> and <see cref="HttpClient"/> properties
        /// will be set to <c>null</c> in this case.
        /// </param>
        /// <param name="noReset">
        /// Optionally prevents the fixture from calling <see cref="CadenceClient.Reset()"/> to
        /// put the Cadence client library into its initial state before the fixture starts as well
        /// as when the fixture itself is reset.
        /// </param>
        /// <param name="emulateProxy">
        /// <b>INTERNAL USE ONLY:</b> Optionally starts a partially functional integrated
        /// <b>cadence-proxy</b> for low-level testing.  Most users should never enable this
        /// because it's probably not going to do what you expect.
        /// </param>
        /// <returns>
        /// <see cref="TestFixtureStatus.Started"/> if the fixture wasn't previously started and
        /// this method call started it or <see cref="TestFixtureStatus.AlreadyRunning"/> if the
        /// fixture was already running.
        /// </returns>
        /// <remarks>
        /// <note>
        /// Some of the <paramref name="settings"/> properties will be ignored including
        /// <see cref="CadenceSettings.Servers"/>.  This will be replaced by the local
        /// endpoint for the Cadence container.  Also, the fixture will connect to the
        /// <b>default</b> Cadence domain by default (unless another is specified).
        /// </note>
        /// <note>
        /// A fresh Cadence client <see cref="Client"/> will be established every time this
        /// fixture is started, regardless of whether the fixture has already been started.  This
        /// ensures that each unit test will start with a client in the default state.
        /// </note>
        /// </remarks>
        public TestFixtureStatus Start(
            CadenceSettings settings = null,
            string image             = "nkubeio/cadence-dev:latest",
            string name             = "cadence-dev",
            string[]            env = null,
            string defaultDomain    = DefaultDomain,
            LogLevel logLevel       = LogLevel.None,
            bool keepConnection     = false,
            bool keepOpen           = false,
            string hostInterface    = null,
            bool noClient           = false,
            bool noReset            = false,
            bool emulateProxy       = false)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(image), nameof(image));

            return(base.Start(
                       () =>
            {
                StartAsComposed(
                    settings:        settings,
                    image:           image,
                    name:            name,
                    env:             env,
                    defaultDomain:   defaultDomain,
                    logLevel:        logLevel,
                    keepConnection:  keepConnection,
                    keepOpen:        keepOpen,
                    noClient:        noClient,
                    noReset:         noReset,
                    emulateProxy:    emulateProxy);
            }));
        }
Esempio n. 6
0
        public Test_FixtureNoConnect(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats
            };

            if (fixture.Start(settings, keepConnection: true, keepOpen: CadenceTestHelper.KeepCadenceServerOpen, noClient: true) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client = CadenceClient.ConnectAsync(fixture.Settings).Result;

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).Wait();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).Wait();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
Esempio n. 7
0
        public static async Task Main(string[] args)
        {
            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://*****:*****@my-company.com", "Jeff");
            }
        }
Esempio n. 8
0
        public Test_Messages(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain   = CadenceFixture.DefaultDomain,
                DefaultTaskList = CadenceFixture.DefaultTaskList,
                Debug           = true,

                //--------------------------------
                // $debug(jeff.lill): DELETE THIS!
                Emulate                = false,
                DebugPrelaunched       = false,
                DebugDisableHandshakes = false,
                DebugDisableHeartbeats = false,
                //--------------------------------
            };

            fixture.Start(settings, keepConnection: true);

            this.fixture     = fixture;
            this.client      = fixture.Connection;
            this.proxyClient = new HttpClient()
            {
                BaseAddress = client.ProxyUri
            };
        }
Esempio n. 9
0
        public Test_RegistrationError(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats
            };

            if (fixture.Start(settings, keepConnection: true, keepOpen: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };

                // NOTE: We're not auto-registering workflows and activities or starting
                //       workers for these unit tests.
            }
            else
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };
            }
        }
Esempio n. 10
0
        public static async Task Main(string[] args)
        {
            try
            {
                var settings = new CadenceSettings("cadence://localhost:7933")
                {
                    DefaultDomain = "test-domain",
                    CreateDomain  = true
                };

                using (var client = await CadenceClient.ConnectAsync(settings))
                {
                    await client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly());

                    await client.StartWorkerAsync(taskList : "hello-tasks");

                    //-------------------------------------
                    // Submit an order to: IOrderWorkflow1

                    var stub1      = client.NewWorkflowStub <IOrderWorkflow1>();
                    var orderTask1 = stub1.ProcessAsync();

                    // Attempt to cancel it via a synchronous signal.

                    var cancelled1 = await stub1.CancelAsync();

                    // Wait for order processing to complete.  The result will
                    // be FALSE if the order was cancelled.

                    var result1 = await orderTask1;

                    //-------------------------------------
                    // Submit an order to: IOrderWorkflow2

                    var stub2      = client.NewWorkflowStub <IOrderWorkflow2>();
                    var orderTask2 = stub2.ProcessAsync();

                    // Attempt to cancel it via a synchronous signal.

                    var cancelled2 = await stub2.CancelAsync();

                    // Wait for order processing to complete.  The result will
                    // be FALSE if the order was cancelled.

                    var result2 = await orderTask2;

                    //-------------------------------------

                    Console.WriteLine($"RESULT-1: {result1}");
                    Console.WriteLine($"RESULT-2: {result2}");
                }
            }
            catch (ConnectException)
            {
                Console.Error.WriteLine("Cannot connect to Cadence.  Be sure you've started a");
                Console.Error.WriteLine("local Cadence Docker container via:");
                Console.Error.WriteLine();
                Console.Error.WriteLine("docker run --detach --name cadence-dev -p 7933-7939:7933-7939 -p 8088:8088 nkubeio/cadence-dev");
            }
        }
Esempio n. 11
0
        public static async Task Main(string[] args)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                await client.RegisterAssemblyAsync(System.Reflection.Assembly.GetExecutingAssembly());

                await client.StartWorkerAsync("my-tasks");

                // Invoke the workflow and then query it's status a few times.

                var stub = client.NewWorkflowStub <IMyWorkflow>();
                var task = stub.DoItAsync();

                for (int i = 0; i < 5; i++)
                {
                    await Task.Delay(TimeSpan.FromSeconds(2.5));

                    Console.WriteLine(await stub.GetStatusAsync());
                }

                await task;
            }
        }
Esempio n. 12
0
        public Test_Replay(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            if (fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client;

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).WaitWithoutAggregate();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
Esempio n. 13
0
        public static async Task Main(string[] args)
        {
            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                var stub = client.NewWorkflowFutureStub <ICronWorkflow>(
                    "backup",
                    new WorkflowOptions()
                {
                    // Run the workflow every day at 1:00am UTC:
                    CronSchedule = "0 1 * * *"
                });;

                await stub.StartAsync();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// <para>
        /// Starts a Cadence container if it's not already running.  You'll generally want
        /// to call this in your test class constructor instead of <see cref="ITestFixture.Start(Action)"/>.
        /// </para>
        /// <note>
        /// You'll need to call <see cref="StartAsComposed(CadenceSettings, string, string, string, Neon.Diagnostics.LogLevel, bool, bool, bool, bool)"/>
        /// instead when this fixture is being added to a <see cref="ComposedFixture"/>.
        /// </note>
        /// </summary>
        /// <param name="settings">Optional Cadence settings.</param>
        /// <param name="name">Optionally specifies the Cadence container name (defaults to <c>cadence-dev</c>).</param>
        /// <param name="composeFile">
        /// <para>
        /// Optionally specifies the Temporal Docker compose file text.  This defaults to
        /// <see cref="DefaultComposeFile"/> which configures Temporal server to start with
        /// a new Cassandra database instance listening on port <b>9042</b> as well as the
        /// Temporal web UI running on port <b>8088</b>.  Temporal server is listening on
        /// its standard gRPC port <b>7233</b>.
        /// </para>
        /// <para>
        /// You may specify your own Docker compose text file to customize this by configuring
        /// a different backend database, etc.
        /// </para>
        /// </param>
        /// <param name="defaultDomain">Optionally specifies the default domain for the fixture's client.  This defaults to <b>test-domain</b>.</param>
        /// <param name="logLevel">Specifies the Cadence log level.  This defaults to <see cref="Neon.Diagnostics.LogLevel.None"/>.</param>
        /// <param name="reconnect">
        /// Optionally specifies that a new Cadence connection <b>should</b> be established for each
        /// unit test case.  By default, the same connection will be reused which will save about a
        /// second per test.
        /// </param>
        /// <param name="keepRunning">
        /// Optionally indicates that the container should remain running after the fixture is disposed.
        /// This is handy for using the Temporal web UI for port mortems after tests have completed.
        /// </param>
        /// <param name="noClient">
        /// Optionally disables establishing a client connection when <c>true</c>
        /// is passed.  The <see cref="Client"/> and <see cref="HttpClient"/> properties
        /// will be set to <c>null</c> in this case.
        /// </param>
        /// <param name="noReset">
        /// Optionally prevents the fixture from calling <see cref="CadenceClient.Reset()"/> to
        /// put the Cadence client library into its initial state before the fixture starts as well
        /// as when the fixture itself is reset.
        /// </param>
        /// <returns>
        /// <see cref="TestFixtureStatus.Started"/> if the fixture wasn't previously started and
        /// this method call started it or <see cref="TestFixtureStatus.AlreadyRunning"/> if the
        /// fixture was already running.
        /// </returns>
        /// <remarks>
        /// <note>
        /// Some of the <paramref name="settings"/> properties will be ignored including
        /// <see cref="CadenceSettings.Servers"/>.  This will be replaced by the local
        /// endpoint for the Cadence container.  Also, the fixture will connect to the
        /// <b>default</b> Cadence domain by default (unless another is specified).
        /// </note>
        /// <note>
        /// A fresh Cadence client <see cref="Client"/> will be established every time this
        /// fixture is started, regardless of whether the fixture has already been started.  This
        /// ensures that each unit test will start with a client in the default state.
        /// </note>
        /// </remarks>
        public TestFixtureStatus Start(
            CadenceSettings settings = null,
            string name          = "cadence-dev",
            string composeFile   = DefaultComposeFile,
            string defaultDomain = DefaultDomain,
            LogLevel logLevel    = LogLevel.None,
            bool reconnect       = false,
            bool keepRunning     = false,
            bool noClient        = false,
            bool noReset         = false)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(composeFile), nameof(composeFile));

            return(base.Start(
                       () =>
            {
                StartAsComposed(
                    settings:        settings,
                    name:            name,
                    composeFile:     composeFile,
                    defaultDomain:   defaultDomain,
                    logLevel:        logLevel,
                    reconnect:       reconnect,
                    keepRunning:     keepRunning,
                    noClient:        noClient,
                    noReset:         noReset);
            }));
        }
Esempio n. 15
0
        /// <summary>
        /// Used to start the fixture within a <see cref="ComposedFixture"/>.
        /// </summary>
        /// <param name="settings">Optional Cadence settings.</param>
        /// <param name="image">Optionally specifies the Cadence container image (defaults to <b>nkubeio/cadence-test:latest</b>).</param>
        /// <param name="name">Optionally specifies the Cadence container name (defaults to <c>cb-test</c>).</param>
        /// <param name="env">Optional environment variables to be passed to the Cadence container, formatted as <b>NAME=VALUE</b> or just <b>NAME</b>.</param>
        /// <param name="defaultDomain">Optionally specifies the default domain for the fixture's client.  This defaults to <b>test-domain</b>.</param>
        /// <param name="defaultTaskList">Optionally specifies the default task list for the fixture's client.  This defaults to <b>test-tasks</b>.</param>
        /// <param name="keepConnection">
        /// Optionally specifies that a new Cadence connection <b>should not</b> be established for each
        /// unit test case.  The same connection will be reused which will save about a second per test.
        /// </param>
        /// <param name="keepOpen">
        /// Optionally indicates that the container should continue to run after the fixture is disposed.
        /// </param>
        /// <param name="emulateProxy">
        /// <b>INTERNAL USE ONLY:</b> Optionally starts a partially functional integrated
        /// <b>cadence-proxy</b> for low-level testing.  Most users should never enable this
        /// because it's probably not going to do what you expect.
        /// </param>
        /// <remarks>
        /// <note>
        /// A fresh Cadence client <see cref="Connection"/> will be established every time this
        /// fixture is started, regardless of whether the fixture has already been started.  This
        /// ensures that each unit test will start with a client in the default state.
        /// </note>
        /// </remarks>
        public void StartAsComposed(
            CadenceSettings settings = null,
            string image             = "nkubeio/cadence-test:latest",
            string name             = "cadence-test",
            string[]            env = null,
            string defaultDomain    = DefaultDomain,
            string defaultTaskList  = DefaultTaskList,
            bool keepConnection     = false,
            bool keepOpen           = false,
            bool emulateProxy       = false)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(image));

            base.CheckWithinAction();

            if (!IsRunning)
            {
                // Start the fixture
                base.StartAsComposed(name, image,
                                     new string[]
                {
                    "--detach",
                    "-p", "7933-7939:7933-7939",
                    "-p", "8088:8088"
                },
                                     env: env,
                                     keepOpen: keepOpen);

                Thread.Sleep(warmupDelay);

                // Initialize the settings.

                settings = settings ?? new CadenceSettings()
                {
                    CreateDomain    = true,
                    DefaultDomain   = defaultDomain,
                    DefaultTaskList = defaultTaskList
                };

                settings.Servers.Clear();
                settings.Servers.Add($"http://localhost:{NetworkPorts.Cadence}");

                settings.Emulate = emulateProxy || settings.Emulate;

                this.settings       = settings;
                this.keepConnection = keepConnection;

                // Establish the Cadence connection.

                Connection = CadenceClient.ConnectAsync(settings).Result;

                ConnectionClient = new HttpClient()
                {
                    BaseAddress = Connection.ListenUri
                };
            }
        }
Esempio n. 16
0
        public Test_EndToEnd(CadenceFixture fixture, ITestOutputHelper outputHelper)
        {
            TestHelper.ResetDocker(this.GetType());

            testWriter = new TestOutputWriter(outputHelper);

            // Initialize the Cadence fixture.

            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            if (fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };

                // Setup a service for activity dependency injection testing if it doesn't
                // already exist.

                if (NeonHelper.ServiceContainer.GetService <ActivityDependency>() == null)
                {
                    NeonHelper.ServiceContainer.AddSingleton(typeof(ActivityDependency), new ActivityDependency()
                    {
                        Hello = "World!"
                    });
                }

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).WaitWithoutAggregate();
            }
            else
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };
            }
        }
Esempio n. 17
0
        public static async Task UntypedStub()
        {
            #region code_untyped
            var settings = new CadenceSettings()
            {
                // This specifies the default domain for operations initiated by the
                // client connected below (this can be overridden for specific
                // operations.

                DefaultDomain = "Acme-PROD",

                // Host/port for at least one of the Cadence cluster servers:

                Servers = new List <string>()
                {
                    "cadence://*****:*****@lilltek.com", "Test subject", "This is a test email.");

                // Wait for the workflow to complete and return it's result.  Note that we need
                // to explicitly specify the result [bool] type as a generic type parameter.
                // You need to ensure that this matches the workflow implementation as well.

                var success = await stub.GetResultAsync <bool>();

                if (success)
                {
                    Console.WriteLine("Email SENT!");
                }
                else
                {
                    Console.WriteLine("Email FAILED!");
                }
            }
            #endregion
        }
Esempio n. 18
0
        public static async Task Main(string[] args)
        {
            // Initialize the logger.

            LogManager.Default.SetLogLevel("info");

            logger = LogManager.Default.GetLogger(typeof(Program));
            logger.LogInfo("Starting workflow service");

            try
            {
                // Connect to Cadence

                var settings = new CadenceSettings()
                {
                    DefaultDomain = "my-domain",
                    CreateDomain  = true,
                    Servers       = new List <string>()
                    {
                        "cadence://localhost:7933"
                    }
                };

                using (var client = await CadenceClient.ConnectAsync(settings))
                {
                    // Register your workflow and activity implementations to let
                    // Cadence know we're open for business.

                    await client.RegisterAssemblyAsync(System.Reflection.Assembly.GetExecutingAssembly());

                    await client.StartWorkerAsync("my-tasks");

                    // Spin forever, processing workflows and activities assigned by Cadence.

                    while (true)
                    {
                        await Task.Delay(TimeSpan.FromMinutes(5));
                    }
                }
            }
            catch (Exception e)
            {
                logger.LogError(e);
            }
            finally
            {
                logger.LogInfo("Exiting workflow service");
            }
        }
Esempio n. 19
0
        public Test_Settings(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats
            };

            this.fixture = fixture;

            fixture.Start(settings, keepConnection: true, keepOpen: CadenceTestHelper.KeepCadenceServerOpen, noClient: true);
        }
Esempio n. 20
0
        public Test_MultiClient(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            this.fixture = fixture;

            fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen, noClient: true);
        }
Esempio n. 21
0
        public Test_StubManager(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain   = CadenceFixture.DefaultDomain,
                DefaultTaskList = CadenceFixture.DefaultTaskList,
                Debug           = true,
            };

            fixture.Start(settings, keepConnection: true);

            this.fixture     = fixture;
            this.client      = fixture.Connection;
            this.proxyClient = new HttpClient()
            {
                BaseAddress = client.ProxyUri
            };
        }
Esempio n. 22
0
        public Test_StubManager(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain = CadenceFixture.DefaultDomain,
                LogLevel      = CadenceTestHelper.LogLevel,
                Debug         = CadenceTestHelper.Debug,
            };

            fixture.Start(settings, keepConnection: true);

            this.fixture     = fixture;
            this.client      = fixture.Client;
            this.proxyClient = new HttpClient()
            {
                BaseAddress = client.ProxyUri
            };
        }
Esempio n. 23
0
        /// <summary>
        /// <para>
        /// Starts a Cadence container if it's not already running.  You'll generally want
        /// to call this in your test class constructor instead of <see cref="ITestFixture.Start(Action)"/>.
        /// </para>
        /// <note>
        /// You'll need to call <see cref="StartAsComposed(CadenceSettings, string, string, string[], string, string, bool, bool, bool)"/>
        /// instead when this fixture is being added to a <see cref="ComposedFixture"/>.
        /// </note>
        /// </summary>
        /// <param name="settings">Optional Cadence settings.</param>
        /// <param name="image">Optionally specifies the Cadence container image (defaults to <b>nkubeio/couchbase-test:latest</b>).</param>
        /// <param name="name">Optionally specifies the Cadence container name (defaults to <c>cadence-test</c>).</param>
        /// <param name="env">Optional environment variables to be passed to the Cadence container, formatted as <b>NAME=VALUE</b> or just <b>NAME</b>.</param>
        /// <param name="defaultDomain">Optionally specifies the default domain for the fixture's client.  This defaults to <b>test-domain</b>.</param>
        /// <param name="defaultTaskList">Optionally specifies the default task list for the fixture's client.  This defaults to <b>test-tasks</b>.</param>
        /// <param name="keepConnection">
        /// Optionally specifies that a new Cadence connection <b>should not</b> be established for each
        /// unit test case.  The same connection will be reused which will save about a second per test.
        /// </param>
        /// <param name="keepOpen">
        /// Optionally indicates that the container should continue to run after the fixture is disposed.
        /// </param>
        /// <param name="emulateProxy">
        /// <b>INTERNAL USE ONLY:</b> Optionally starts a partially functional integrated
        /// <b>cadence-proxy</b> for low-level testing.  Most users should never enable this
        /// because it's probably not going to do what you expect.
        /// </param>
        /// <returns>
        /// <see cref="TestFixtureStatus.Started"/> if the fixture wasn't previously started and
        /// this method call started it or <see cref="TestFixtureStatus.AlreadyRunning"/> if the
        /// fixture was already running.
        /// </returns>
        /// <remarks>
        /// <note>
        /// Some of the <paramref name="settings"/> properties will be ignored including
        /// <see cref="CadenceSettings.Servers"/>.  This will be replaced by the local
        /// endpoint for the Cadence container.  Also, the fixture will connect to the
        /// <b>default</b> Cadence domain by default (unless another is specified).
        /// </note>
        /// <note>
        /// A fresh Cadence client <see cref="Connection"/> will be established every time this
        /// fixture is started, regardless of whether the fixture has already been started.  This
        /// ensures that each unit test will start with a client in the default state.
        /// </note>
        /// </remarks>
        public TestFixtureStatus Start(
            CadenceSettings settings = null,
            string image             = "nkubeio/cadence-test:latest",
            string name             = "cadence-test",
            string[]            env = null,
            string defaultDomain    = DefaultDomain,
            string defaultTaskList  = DefaultTaskList,
            bool keepConnection     = false,
            bool keepOpen           = false,
            bool emulateProxy       = false)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(image));

            return(base.Start(
                       () =>
            {
                StartAsComposed(settings, image, name, env, defaultDomain, defaultTaskList, keepConnection, keepOpen, emulateProxy);
            }));
        }
Esempio n. 24
0
        public static async Task Main(string[] args)
        {
            // Configure the settings name such that they will be injected
            // into the email activity when it's constructed.
            //
            // Note that we did this before calling RegisterAssemblyAsync() below.
            // Dependencies added after activities have been registered will be
            // ignored.

            NeonHelper.ServiceContainer.AddSingleton(typeof(MailSettings), new MailSettings()
            {
                MailServer = "mail.my-company.com"
            });

            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                // Register your workflow and activity implementations to let
                // Cadence know we're open for business.

                await client.RegisterAssemblyAsync(System.Reflection.Assembly.GetExecutingAssembly());

                await client.StartWorkerAsync("my-tasks");

                // Invoke the workflow.

                var workflowStub = client.NewWorkflowStub <IEmailWorkflow>();

                await workflowStub.SendMessagesAsync();
            }
        }
Esempio n. 25
0
        public CadenceTests(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain = "test-domain",
                LogLevel      = LogLevel.Info,
                CreateDomain  = true            // <-- this ensures that the default domain exists
            };

            // This starts/restarts the [nforgeio/cadence-dev] container for the first test
            // run in this class.  Subsequent tests run from the class will use the existing
            // container instance, saving time by not having to wait for Cadence and Cassandra
            // to spin up and be ready for business.
            //
            // The [keepOpen=true] parameter tells the fixture to let the container continue running
            // after all of the tests have completed.  This is useful for examining workflow histories
            // via the Cadence UX after the tests have completed.  You can view the Cadence portal at
            //
            //      http://localhost:8088
            //
            // You can pass [keepOpen=false] to have the fixture remove the container after the
            // test run if you wish.

            if (fixture.Start(settings, reconnect: true, keepRunning: true) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client;

                // Register the test workflow and activity implementations
                // from this assembly and start the worker.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();
                client.StartWorkerAsync("test-tasks").WaitWithoutAggregate();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
Esempio n. 26
0
        public Test_Messages(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats
            };

            fixture.Start(settings, keepConnection: true);

            this.fixture     = fixture;
            this.client      = fixture.Client;
            this.proxyClient = new HttpClient()
            {
                BaseAddress = client.ProxyUri
            };
        }
Esempio n. 27
0
        public Test_StubManager(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain  = CadenceFixture.DefaultDomain,
                LogLevel       = CadenceTestHelper.LogLevel,
                Debug          = CadenceTestHelper.Debug,
                ClientIdentity = CadenceTestHelper.ClientIdentity
            };

            fixture.Start(settings, reconnect: true);

            this.fixture     = fixture;
            this.client      = fixture.Client;
            this.proxyClient = new HttpClient()
            {
                BaseAddress = client.ProxyUri
            };
        }
Esempio n. 28
0
        public static async Task Main(string[] args)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                await client.RegisterAssemblyAsync(System.Reflection.Assembly.GetExecutingAssembly());

                await client.StartWorkerAsync("my-tasks");

                // Invoke the workflow, send it some signals and very that
                // it changed its state to the signal value.

                var stub = client.NewWorkflowStub <IMyWorkflow>();
                var task = stub.DoItAsync();

                await stub.SignalAsync("signal #1");

                Console.WriteLine(await stub.GetStatusAsync());

                await stub.SignalAsync("signal #2");

                Console.WriteLine(await stub.GetStatusAsync());

                // This signal completes the workflow.

                await stub.SignalAsync("done");

                await task;
            }
        }
Esempio n. 29
0
        public static async Task Main(params string[] args)
        {
            var settings = new CadenceSettings()
            {
                // This specifies the default domain for operations initiated by the
                // client connected below (this can be overridden for specific
                // operations.

                DefaultDomain = "Acme-PROD",

                // Host/port for at least one of the Cadence cluster servers:

                Servers = new List <string>()
                {
                    "cadence://*****:*****@lilltek.com", "Test subject", "This is a test email.");

                if (success)
                {
                    Console.WriteLine("Email SENT!");
                }
                else
                {
                    Console.WriteLine("Email FAILED!");
                }
            }
        }
Esempio n. 30
0
        public static async Task Main(string[] args)
        {
            // Connect to Cadence

            var settings = new CadenceSettings()
            {
                DefaultDomain = "my-domain",
                CreateDomain  = true,
                Servers       = new List <string>()
                {
                    "cadence://localhost:7933"
                }
            };

            using (var client = await CadenceClient.ConnectAsync(settings))
            {
                // Register your workflow implementation to let Cadence
                // know we're open for business.

                await client.RegisterWorkflowAsync <HelloWorkflow>();

                await client.StartWorkerAsync("my-tasks");

                #region code
                // Invoke a workflow with options:

                var stub = client.NewWorkflowStub <IHelloWorkflow>(
                    new WorkflowOptions()
                {
                    WorkflowId             = "my-ultimate-workflow",
                    ScheduleToStartTimeout = TimeSpan.FromMinutes(5)
                });

                Console.WriteLine(await stub.HelloAsync("Jeff"));
                #endregion
            }
        }