File tree Expand file tree Collapse file tree 10 files changed +159
-14
lines changed
src/puppetlabs/trapperkeeper
test/puppetlabs/trapperkeeper Expand file tree Collapse file tree 10 files changed +159
-14
lines changed Original file line number Diff line number Diff line change @@ -4,17 +4,17 @@ set -uexo pipefail
4
4
5
5
usage () { echo " Usage: $( basename " $0 " ) " ; }
6
6
misuse () { usage 1>&2 ; exit 2; }
7
- tk () { lein trampoline run " $@ " ; }
8
7
9
8
test $# -eq 0 || misuse
10
9
11
- tmpdir=" $( mktemp -d " test-top-level-cli -XXXXXX" ) "
10
+ tmpdir=" $( mktemp -d " test-custom-exit-behavior -XXXXXX" ) "
12
11
tmpdir=" $( cd " $tmpdir " && pwd) "
13
12
trap " $( printf ' rm -rf %q' " $tmpdir " ) " EXIT
14
13
15
14
rc=0
16
- tk -d -b ext/test/lib/custom-exit-behavior/bootstrap.cfg \
17
- 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
15
+ ./tk -cp " $( pwd) /test" -- \
16
+ -d -b <( echo puppetlabs.trapperkeeper.custom-exit-behavior-test/custom-exit-behavior-test-service) \
17
+ 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
18
18
cat " $tmpdir /out" " $tmpdir /err"
19
19
test " $rc " -eq 7
20
20
grep -F ' Some excitement!' " $tmpdir /out"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ test $# -eq 0 || misuse
9
9
10
10
ext/test/top-level-cli
11
11
ext/test/custom-exit-behavior
12
+ ext/test/signal-handling
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -uexo pipefail
4
+
5
+ usage () { echo " Usage: $( basename " $0 " ) " ; }
6
+ misuse () { usage 1>&2 ; exit 2; }
7
+
8
+ await-file ()
9
+ (
10
+ local target=" $1 "
11
+ set +x
12
+ while ! test -e " $target " ; do sleep 0.1; done
13
+ )
14
+
15
+ tk_pid=' '
16
+ tmpdir=' '
17
+ on-exit ()
18
+ {
19
+ if test " $tk_pid " ; then
20
+ kill " $tk_pid "
21
+ status=0
22
+ wait " $tk_pid " || status=$?
23
+ set +x
24
+ echo tk exited with status " $status (143 is likely)" 1>&2
25
+ set -x
26
+ fi
27
+ rm -rf " $tmpdir "
28
+ }
29
+ trap on-exit EXIT
30
+
31
+ test $# -eq 0 || misuse
32
+
33
+ tmpdir=" $( mktemp -d " test-signal-handling-XXXXXX" ) "
34
+ tmpdir=" $( cd " $tmpdir " && pwd) "
35
+
36
+ # Start the test server, which repeatedly writes to the configured
37
+ # target file, and make sure the target changes after a config file
38
+ # change and signal.
39
+
40
+ target_1=" $tmpdir /target-1"
41
+ target_2=" $tmpdir /target-2"
42
+
43
+ cat > " $tmpdir /config.json" << EOS
44
+ {"signal-test-target": "$target_1 "}
45
+ EOS
46
+
47
+ ./tk -cp " $( pwd) /test" -- \
48
+ --config " $tmpdir /config.json" \
49
+ -b <( echo puppetlabs.trapperkeeper.signal-handling-test/signal-handling-test-service) &
50
+ tk_pid=$!
51
+
52
+ await-file " $target_1 "
53
+ test exciting = " $( < " $target_1 " ) "
54
+
55
+ test ! -e " $target_2 "
56
+ cat > " $tmpdir /config.json" << EOS
57
+ {"signal-test-target": "$target_2 "}
58
+ EOS
59
+
60
+ kill -HUP " $tk_pid "
61
+ await-file " $target_2 "
62
+ test exciting = " $( < " $target_2 " ) "
Original file line number Diff line number Diff line change @@ -14,15 +14,15 @@ trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
14
14
15
15
# # Test handling an unknown option
16
16
rc=0
17
- ./tk --invalid-option 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
17
+ ./tk -- -- invalid-option 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
18
18
cat " $tmpdir /out" " $tmpdir /err"
19
19
test " $rc " -eq 1
20
20
grep -F ' Unknown option: "--invalid-option"' " $tmpdir /err"
21
21
22
22
23
23
# # Test --help
24
24
rc=0
25
- ./tk --help 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
25
+ ./tk -- -- help 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
26
26
cat " $tmpdir /out" " $tmpdir /err"
27
27
test " $rc " -eq 0
28
28
grep -F ' Path to bootstrap config file' " $tmpdir /out"
@@ -32,7 +32,7 @@ test $(wc -c < "$tmpdir/out") -eq 650
32
32
33
33
# # Test handling a missing bootstrap file
34
34
rc=0
35
- ./tk frobnicate ... 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
35
+ ./tk -- frobnicate ... 1> " $tmpdir /out" 2> " $tmpdir /err" || rc=$?
36
36
cat " $tmpdir /out" " $tmpdir /err"
37
37
test " $rc " -eq 1
38
38
grep -F ' Unable to find bootstrap.cfg file via --bootstrap-config' " $tmpdir /err"
Original file line number Diff line number Diff line change 93
93
(log/debug (i18n/trs " Loading bootstrap config from current working directory: ''{0}''" config-file-path))
94
94
[config-file-path]))))
95
95
96
+ (defn- resource [name]
97
+ ; ; Fixes io/resource crashes when context class loader is nil.
98
+ ; ; https://clojure.atlassian.net/browse/CLJ-2431
99
+ (.getResource (or (.getContextClassLoader (Thread/currentThread ))
100
+ (ClassLoader/getSystemClassLoader ))
101
+ name))
102
+
96
103
(schema/defn config-from-classpath :- [(schema/maybe schema/Str)]
97
104
" Check to see if there is a bootstrap config file available on the classpath;
98
105
if so, return it."
99
106
[]
100
- (when-let [classpath-config (io/ resource bootstrap-config-file-name)]
107
+ (when-let [classpath-config (resource bootstrap-config-file-name)]
101
108
(log/debug (i18n/trs " Loading bootstrap config from classpath: ''{0}''" classpath-config))
102
109
[(str classpath-config)]))
103
110
133
140
the config. Throws an exception if there is a problem reading the file or
134
141
the URI can't be loaded"
135
142
[config-path :- schema/Str]
136
- (if (fs/file ? config-path)
143
+ (if (fs/readable ? config-path)
137
144
(line-seq (io/reader (fs/file config-path)))
138
145
(try
139
146
; If it's not a file, attempt to read it as a URI
Original file line number Diff line number Diff line change 58
58
(edn/read (PushbackReader. (io/reader file)))
59
59
60
60
#{" .yaml" " .yml" }
61
- (yaml/parse-string (slurp file))))
61
+ (yaml/parse-string (slurp file))
62
+
63
+ (throw (IllegalArgumentException.
64
+ (i18n/trs " Config file {0} must end in .conf or other recognized extension"
65
+ (-> file str pr-str))))))
62
66
63
67
(defn override-restart-file-from-cli-data
64
68
[config-data cli-data]
Original file line number Diff line number Diff line change 210
210
(defn main
211
211
" Launches the trapperkeeper framework. This function blocks until
212
212
trapperkeeper is shut down. This may be called directly, but is also
213
- called by `puppetlabs.trapperkeeper.core /-main` if you use
213
+ called by `puppetlabs.trapperkeeper.main /-main` if you use
214
214
`puppetlabs.trapperkeeper.core` as the `:main` namespace in your
215
215
leinengen project. Never returns (calls System/exit) after argument
216
216
processing errors, `--help` requests, or calls to `request-shutdown`
Original file line number Diff line number Diff line change
1
+ (ns puppetlabs.trapperkeeper.signal-handling-test
2
+ (:require
3
+ [puppetlabs.trapperkeeper.core :as core]))
4
+
5
+ (defn- start-test [context get-in-config]
6
+ (let [continue? (atom true )
7
+ thread (future
8
+ (try ; ; future just discards top-level exceptions
9
+ (while @continue?
10
+ (let [target (get-in-config [:signal-test-target ])]
11
+ (assert target)
12
+ (Thread/sleep 200 )
13
+ (spit target " exciting" )))
14
+ (catch Throwable ex
15
+ (prn ex)
16
+ (throw ex))))]
17
+ (assoc context
18
+ :finish-signal-test
19
+ (fn exit-signal-test []
20
+ (reset! continue? false )
21
+ @thread))))
22
+
23
+ (defn- stop-test [{:keys [finish-signal-test] :as context}]
24
+ (finish-signal-test )
25
+ context )
26
+
27
+ (defprotocol SignalHandlingTestService )
28
+
29
+ (core/defservice signal-handling-test-service
30
+ SignalHandlingTestService
31
+ [[:ConfigService get-in-config]]
32
+ (init [this context] context)
33
+ (start [this context] (start-test context get-in-config))
34
+ (stop [this context] (stop-test context)))
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
- set -e
3
+ set -ueo pipefail
4
+
5
+ usage () { echo " Usage: tk JVM_ARG ... -- TK_ARG ..." ; }
6
+ misuse () { usage 1>&2 ; exit 2; }
4
7
5
8
jar_glob=' trapperkeeper-*-SNAPSHOT-standalone.jar'
6
9
10
+ # Believe last -cp wins for java, and here, any final -cp path will be
11
+ # placed in front of the jar.
12
+
13
+ cp=' '
14
+ jvm_args=()
15
+ while test $# -gt 0; do
16
+ case " $1 " in
17
+ -h|--help)
18
+ usage
19
+ exit 0
20
+ ;;
21
+ -cp)
22
+ shift
23
+ test $# -gt 0 || misuse
24
+ cp=" $1 "
25
+ shift
26
+ ;;
27
+ --)
28
+ shift
29
+ break
30
+ ;;
31
+ * )
32
+ shift
33
+ jvm_args+=(" $1 " )
34
+ ;;
35
+ esac
36
+ done
37
+
7
38
if test " ${TRAPPERKEEPER_JAR:- } " ; then
8
39
jar=" $TRAPPERKEEPER_JAR "
9
40
else
@@ -28,4 +59,11 @@ if ! test -e "$jar"; then
28
59
exit 2
29
60
fi
30
61
31
- exec java -jar " $jar " " $@ "
62
+ set -x
63
+ if test " $cp " ; then
64
+ cp=" $cp :$jar "
65
+ else
66
+ cp=" $jar "
67
+ fi
68
+
69
+ exec java -cp " $cp " clojure.main -m puppetlabs.trapperkeeper.main " $@ "
You can’t perform that action at this time.
0 commit comments