我正在使用星号测试套件并创建自定义测试。但我正在尝试用 java 替换一些 python 脚本。
问题是我不知道如何使用“asterisk java”为每个使用自定义拨号计划创建两个星号实例。
好消息是,除了最上面的 run-tests.py 脚本之外,Asterisk 测试套件与语言无关。您会发现用 python、lua 甚至 bash 编写的测试。Java 将是一个新的补充。我不建议尝试重写 runtests.py - 你不会得到很多回报,尽管我想你可以这样做。
至于对 Asterisk 实例进行“沙盒化”,使其不会与其他 Asterisk 实例发生冲突,并且您可以同时运行任意数量,您必须采取许多步骤才能使其正常工作。幸运的是,如果您查看 asterisk.py 模块(在 lib/python/asterisk 中) - 或 asttest/lib/lua 中的 astlib.lua - 您将有一些工作示例,说明必须完成的所有工作发生。
至少,您需要执行以下操作:
例如,让我们以 confbridge python 测试为例。它生成了三个 Asterisk 实例。第一次运行时,它会退出并查看 /tmp/asterisk-testsuite 是否存在。可以说不是。所以我们创建了那个目录。
/tmp/asterisk-testsuite/
We then see that the test being run lives in tests/apps/confbridge - so we make our test directory, since we haven't run yet either.
/tmp/asterisk-testsuite/apps/confbridge
Now it gets interesting. We haven't run before, so when we check to see if any astn directories exist in our test directory, we determine that there aren't. So we create three of those directories.
/tmp/asterisk-testsuite/apps/confbridge
/ast1
/ast2
/ast3
Taking only ast1 as an example, we create an asterisk.conf file containing locations to our paths:
[directories](!)
astetcdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk
astmoddir => /tmp/asterisk-testsuite/apps/confbridge/ast1/usr/lib/asterisk/modules
astvarlibdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astdbdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astkeydir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astdatadir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk
astagidir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/lib/asterisk/agi-bin
astspooldir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/spool/asterisk
astrundir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/run/asterisk
astlogdir => /tmp/asterisk-testsuite/apps/confbridge/ast1/var/log/asterisk
[options]
verbose = 5
debug = 5
defaultlanguage = en ; Default language
documentation_language = en_US ; Set the language you want documentation
; displayed in. Value is in the same format as
; locale names.
[compat]
pbx_realtime=1.6
res_agi=1.6
app_set=1.6
We now copy our asterisk.conf into our test directory.
/tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk/asterisk.conf
We would then hardlink the necessary installed module shared objects to the /var/lib/asterisk/modules subdirectory, and hardlink the installed configuration files to the /etc/asterisk subdirectory. Alternatively, for /var/lib/asterisk/modules, we could have just let that use the standard installed modules and not done the hardlinking, if you so desire.
Finally, when we spawn Asterisk, we use the following syntax:
asterisk -f -g -q -m -n -C /tmp/asterisk-testsuite/apps/confbridge/ast1/etc/asterisk/asterisk.conf
Addendum to what I wrote above
There's nothing wrong with Java, but there's also a lot of re-inventing of the wheel you're going to have to do if you decide to go with a new language in the Test Suite - and not just in getting Asterisk spawned. We've written a lot of other stuff into the lua/python libraries that makes your life easier in addition to everything I've described here. Things like common test classes for CDR parsing and manipulation, voicemail manipulation, complex state machine interactions with SIPp, tests that harness multiple SIPp instances and orchestrate them in conjunction with the Test Suite - and we've been particularly focusing on the python libraries as of late. You may want to consider just going with Python - but, if you really love Java, by all means feel free to use that.