我是Pact(消费者驱动的测试)和gradle的新手,我使用这个着名的工作室来尝试使用Java和Pact Brocker https://github.com/Mikuu/Pact-JVM-Example进行Pact,但是当提供者将验证发送给Pact时,它永远不会工作到最后一部分经纪人。它通过REST API手动工作,但使用该项目永远不会发送验证。请帮助理解发生了什么(可能缺少某些东西,某些库或注释?)
当生产者尝试将验证发送到Pact Broker(使用带有./gradlew :example-provider:pactVerify
的gradle的docker中的本地代理)时,我附加调试日志。我想POST请求的主体丢失了。
14:22:59.469 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Opening connection {}->http://localhost:80
14:22:59.469 [DEBUG] [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connecting to localhost/127.0.0.1:80
14:22:59.470 [DEBUG] [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connection established 127.0.0.1:55770<->127.0.0.1:80
14:22:59.470 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Executing request POST /pacts/provider/ExampleProvider/consumer/JunitRuleMultipleInteractionsConsumer/pact-version/e66d465478e1934bca0ad9b905a2f83835af481d/verification-results HTTP/1.1
14:22:59.470 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Target auth state: UNCHALLENGED
14:22:59.470 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Proxy auth state: UNCHALLENGED
14:22:59.492 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Connection can be kept alive indefinitely
14:22:59.493 [DEBUG] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-255: Close connection
14:22:59.493 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Connection discarded
14:22:59.493 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 255][route: {}->http://localhost:80][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
14:22:59.493 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute verifyPact for :example-provider:pactVerify_ExampleProvider'
14:22:59.493 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
14:22:59.493 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':example-provider:pactVerify_ExampleProvider'
14:22:59.493 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Task :example-provider:pactVerify_ExampleProvider'
14:22:59.493 [null] [org.gradle.internal.progress.DefaultBuildOperationExecutor]
14:22:59.493 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Task :example-provider:pactVerify_ExampleProvider' completed
14:22:59.493 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :example-provider:pactVerify_ExampleProvider (Thread[Task worker for ':',5,main]) completed. Took 0.96 secs.
答案 0 :(得分:0)
pact示例似乎缺少一个重要步骤:添加@PactBroker批注
@Pact批注下面,应该有一个批注
@PactBroker(port = PORT_NUM , host = HOST_NAME)
您可以在此处找到示例at the official repo