I hereby claim:
- I am brendonanderson on github.
- I am brendonanderson (https://keybase.io/brendonanderson) on keybase.
- I have a public key ASANHgnG3vq0Ifl8ll6euF4RvJ183yAvJ5VIJa2-lrGpcAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
task stopServer(type: KillProcessTask) { | |
doFirst { | |
kafkaEmbedded?.after() | |
} | |
} |
void 'testConsume'() { | |
given: | |
String key = '1' | |
String json = """{"key":"${key}", "data": "foo"}""" | |
when: | |
postJson('/test', json) | |
then: | |
consume('output-topic', key, 5, 500) |
String consume(String topic, String key, int maxRetries, long pollMs) { | |
int retry = 0 | |
String message = null | |
KafkaConsumer<String, String> consumer = createKafkaConsumer(topic) | |
while (!message && retry < maxRetries) { | |
retry++ | |
ConsumerRecords consumerRecords = consumer.poll(pollMs) | |
consumerRecords.each { ConsumerRecord record -> | |
if (record.key() == key) { |
task startServer(type: SpawnProcessTask) { | |
doFirst { | |
kafkaEmbedded = new KafkaEmbedded(1, true, 1, 'output-topic') | |
kafkaEmbedded.before() | |
bootPort = availablePort() | |
command "java -Dserver.port=${bootPort} -Dspring.kafka.producer.bootstrap-servers=${kafkaEmbedded.getBrokersAsString()} -Dspring.kafka.consumer.group-id=func-test -jar ${projectDir}/build/libs/emb-kafka-${version}.jar" | |
ready 'Started EmbKafkaApplication' // looks for this text to indicate process has started | |
} | |
} |
task functionalTest(type: Test, dependsOn: [assemble, startServer]) { | |
testClassesDir = sourceSets.functionalTest.output.classesDir | |
classpath = sourceSets.functionalTest.runtimeClasspath | |
doFirst { | |
systemProperty('spring.kafka.producer.bootstrap-servers', kafkaEmbedded.getBrokersAsString()) | |
systemProperty('server.port', bootPort) | |
} | |
} | |
functionalTest.finalizedBy('stopServer') |
ratpack { | |
handlers { | |
get('users/:id') { //ex: /users/xyz123 | |
render context.pathTokens['id'] | |
} | |
get('users') { //ex: /users/ | |
render 'no path token' | |
} | |
get('repeatString/:string/:times:[\\d]+') { | |
//ex: /repeatString/X/10 would send back 10 Xs |
dependencies { | |
... | |
compile ratpack.dependency('config') | |
compile ratpack.dependency('jackson') | |
... | |
} |
class MyRequestService { | |
private HttpClient httpClient | |
@Inject | |
MyRequestService(HttpClient httpClient) { | |
this.httpClient = httpClient | |
} | |
Promise<ReceivedResponse> makeRequest(String uri, String body) { |
ratpack { | |
bindings { | |
ConfigData configData = ConfigData.of().yaml(ClassLoader.getSystemResource('application.yml')).build() | |
add new MyModule(configData.get('/environment', String)) | |
} | |
handlers { | |
handler('mymapping') { ComplexClass complexClass -> | |
complexClass.doSomethingCool() | |
... | |
} |