-
Notifications
You must be signed in to change notification settings - Fork 2
/
scratch.clj
248 lines (201 loc) · 8.58 KB
/
scratch.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
;; Copyright (c) 2016 Cognitect, Inc.
;;
;; This file is part of Requestinator.
;;
;; All rights reserved. This program and the accompanying materials
;; are made available under the terms of the Eclipse Public License v1.0
;; which accompanies this distribution, and is available at
;; http://www.eclipse.org/legal/epl-v10.html
(require '[clojure.test.check :as c]
'[clojure.test.check.generators :as gen]
'[clojure.data.json :as json])
;; Can we generate an infinite sequence of values from a generator?
(->> (gen/sample-seq gen/int)
(drop 100000)
(take 10))
(->> "http://petstore.swagger.io/v2/swagger.json"
slurp
(spit "petstore.swagger.json"))
(last (gen/sample (request-generator amended-spec) 100))
(take 3 (gen/sample (request-generator amended-spec)))
(gen/generate
(object-generator
{}
{"properties"
{"foo" {"type" "integer"}
"bar" {"type" "string"}
"quux" {"type" "object"
"properties" {"baaz" {"type" "integer"}}}}}))
(first (generate amended-spec))
(generate-params amended-spec "/pet/findByStatus" "get")
(generate-params amended-spec "/store/order" "post")
(generate-request {:spec amended-spec :op "/pet" :method "post"})
(generate-request {:spec amended-spec :op "/pet" :method "put"})
(generate-request {:spec amended-spec :op "/pet/findByStatus" :method "get"})
(generate-request {:spec amended-spec :op "/pet/findByTags" :method "get"})
(generate-request {:spec amended-spec :op "/pet/{petId}" :method "delete"})
(generate-request {:spec amended-spec :op "/pet/{petId}/uploadImage" :method "post"})
(generate-request {:spec amended-spec :op "/store/order" :method "post"})
(generate-request {:spec amended-spec :op "/store/order/{orderId}" :method "delete"})
(generate-request {:spec amended-spec :op "/store/order/{orderId}" :method "get"})
(let [swagger-url "http://petstore.swagger.io/v2/swagger.json"
amendments (->> "petstore.amendments.json"
io/resource
io/reader
slurp
json/read-str)
spec (-> swagger-url
slurp
json/read-str
(json-helper/amend amendments))
client (http/generate-client (http/cookie-store))
request (first (generate spec))]
(client request))
(let [swagger-url "http://petstore.swagger.io/v2/swagger.json"
amendments (->> "petstore.amendments.json"
io/resource
io/reader
slurp
json/read-str)
spec (-> swagger-url
slurp
json/read-str
(json-helper/amend amendments))
request (generate-request {:spec spec
:op "/pet/{petId}/uploadImage"
:method "post"
:mime-type "multipart/form-data"})
client (http/generate-client (http/cookie-store))]
;;request
(client request)
)
(let [swagger-url "http://petstore.swagger.io/v2/swagger.json"
amendments (->> "petstore.amendments.json"
io/resource
io/reader
slurp
json/read-str)
spec (-> swagger-url
slurp
json/read-str
(json-helper/amend amendments))
now (java.util.Date.)
dir (io/file "/tmp" (format "%TFT%TT" now now))
recorder (file-recorder dir)]
(generate-activity-streams {:spec spec
:agent-count 1
:interarrival-sec 1
:duration-sec 10
:recorder recorder})
dir)
(foo)
(let [in (java.io.FileInputStream. "/tmp/2016-02-11T16:05:24/index.transit")
reader (transit/reader in :json)]
(transit/read reader))
(execute {:fetch-f (file-fetcher "/tmp/2016-02-16T15:15:00")
:record-f (fn [path bytes] (log/debug :path path :bytes (alength bytes)))
:start (java.util.Date.)
:recorder-concurrency 1})
(execute {:fetch-f (file-fetcher "/tmp/2016-02-16T15:15:00")
:record-f (file-recorder "/tmp/2016-02-16T15:15:00/responses")
:start (java.util.Date. (+ (System/currentTimeMillis) 20000))
:recorder-concurrency 1})
;;; File test
(let [swagger-url "http://petstore.swagger.io/v2/swagger.json"
amendments (->> "petstore.amendments.json"
io/resource
io/reader
slurp
json/read-str)
spec (-> swagger-url
slurp
json/read-str
(json-helper/amend amendments))
now (java.util.Date.)
dir (io/file "/tmp" (format "%TFT%TT" now now))
recorder (file-recorder dir)]
(generate-activity-streams {:spec spec
:agent-count 10
:interarrival-sec 1
:duration-sec 60
:recorder recorder})
dir)
(let [dir "/tmp/2016-02-16T15:43:39"]
(execute {:fetch-f (file-fetcher dir)
:record-f (file-recorder (io/file dir "responses"))
:start (java.util.Date.)
:recorder-concurrency 5}))
;;; S3 Test
(let [swagger-url "http://petstore.swagger.io/v2/swagger.json"
amendments (->> "petstore.amendments.json"
io/resource
io/reader
slurp
json/read-str)
spec (-> swagger-url
slurp
json/read-str
(json-helper/amend amendments))
now (java.util.Date.)
recorder (s3-recorder (s3/client)
"com.cognitect.requestinator.test"
(format "test/%TFT%TT" now now))]
(generate-activity-streams {:spec spec
:agent-count 10
:interarrival-sec 1
:duration-sec 60
:recorder recorder}))
(let [bucket "com.cognitect.requestinator.test"
prefix "test/2016-02-16T16:28:39"
now (java.util.Date.)
folder (format "responses/%TFT%TT" now now)]
(execute {:fetch-f (s3-fetcher (s3/client) bucket prefix)
:record-f (s3-recorder (s3/client) bucket (s3/combine-paths prefix
folder))
:start (java.util.Date.)
:recorder-concurrency 5}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(refresh)
(let [now (java.util.Date.)
now-dir (str "file:///tmp/" (format "%TFT%TT" now now))]
(main/main* "generate"
"-s" "http://petstore.swagger.io/v2/swagger.json"
"-a" "file:resources/petstore.amendments.json"
"-d" now-dir
"-n" 3
"-i" 1.5
"-t" 21.2))
(let [now (java.util.Date.)
now-dir (str "file:///tmp/" (format "%TFT%TT" now now))]
(main/main* "generate"
"--spec-uri" "http://petstore.swagger.io/v2/swagger.json"
"--destination" now-dir
"--agent-count" "3"
"--interarrival-sec" "0.5"
"--duration-sec" "60"))
(let [now (java.util.Date.)
now-dir (str "file:///tmp/" (format "%TFT%TT" now now))]
(main/main* "generate"
"--spec-uri" "http://petstore.swagger.io/v2/swagger.json"
"--destination" now-dir
"--agent-count" "3"
"--interarrival-sec" "0.5"
"--duration-sec" "60")
(main/main* "execute"
"--source" now-dir
"--destination" (str now-dir "/responses")
"--recorder-concurrency" "5"))
(let [dir "/tmp/2016-02-18T15:33:16/"
{:keys [status]} (execute {:fetch-f (file-fetcher dir)
:record-f (file-recorder (io/file dir "responses2"))
:start (java.util.Date.)
:recorder-concurrency 5})]
(loop []
(when-let [msg (<!! status)]
(println msg)
(recur))))
(let [dir "/tmp/2016-02-18T15:33:16/"]
(execute {:fetch-f (file-fetcher dir)
:record-f (file-recorder (io/file dir "responses2"))
:start (java.util.Date.)
:recorder-concurrency 5}))