1 /*******************************************************************************
2 
3     Test for ocean.util.app.ext.TaskExt
4 
5     Copyright:
6         Copyright (c) 2017 dunnhumby Germany GmbH.
7         All rights reserved.
8 
9     License:
10         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11         Alternatively, this file may be distributed under the terms of the Tango
12         3-Clause BSD License (see LICENSE_BSD.txt for details).
13 
14 *******************************************************************************/
15 
16 module integrationtest.taskext_daemon.main;
17 
18 import ocean.meta.types.Qualifiers;
19 import ocean.util.app.DaemonApp;
20 import ocean.util.test.DirectorySandbox;
21 import ocean.task.Task;
22 import ocean.task.Scheduler;
23 import ocean.core.Test;
24 import ocean.io.device.File;
25 import Version;
26 
27 class HarmlessException : Exception
28 {
29     this ( )
30     {
31         super("");
32     }
33 }
34 
35 class AnotherTask : Task
36 {
37     override public void run ( )
38     {
39         auto stats = theScheduler.getStats();
40         // must be 1 (only main app task), not 2, as this task is configured
41         // to run via dedicated worker fiber pool
42         test!("==")(stats.worker_fiber_busy, 1);
43     }
44 }
45 
46 class TestApp : DaemonApp
47 {
48     this ( )
49     {
50         istring name = "test app";
51         istring desc = name;
52         DaemonApp.OptionalSettings settings;
53         settings.use_task_ext = true;
54         super(name, desc, VersionInfo.init, settings);
55     }
56 
57     override int run ( Arguments args, ConfigParser config )
58     {
59         theScheduler.exception_handler = (Task, Exception e)
60         {
61             throw e;
62         };
63 
64         test(Task.getThis() !is null);
65         test(isSchedulerUsed());
66         auto stats = theScheduler.getStats();
67         test!("==")(stats.worker_fiber_total, 3);
68         theScheduler.schedule(new AnotherTask);
69         throw new HarmlessException;
70     }
71 }
72 
73 version (unittest) {} else
74 int main ( istring[] cl_args )
75 {
76     with (DirectorySandbox.create(["etc", "log"]))
77     {
78         scope (success)
79             remove();
80         scope (failure)
81             exitSandbox();
82 
83         File.set("etc/config.ini", "[SCHEDULER]
84 worker_fiber_limit = 3
85 specialized_pools =
86     integrationtest.taskext_daemon.main.AnotherTask:10240
87     whatever:1024
88 [LOG.Root]
89 console = false");
90 
91         auto app = new TestApp;
92 
93         testThrown!(HarmlessException)(app.main(cl_args));
94     }
95 
96     return 0;
97 }