dreamhead / moco

Easy Setup Stub Server
MIT License
4.37k stars 1.08k forks source link

Asynchronous, Duplicate key Accept-Encoding #340

Closed comeCU closed 1 year ago

comeCU commented 1 year ago

version:

moco-runner-1.5.0-standalone.jar

configuration file:

[
   {
        "description":"异步事件",
        "request":{
            "uri":"/eventAsync",
            "method":"get"
        },
        "response":{
            "text":"eventeventAsync ..."
        },
        "on":{
            "complete":{
                "async":"true",
                "latency":5000,
                "get" : {
                    "url":"https://mysite-xxxxxx.com"
                }
            }
        }
    }
]

console log:

java -jar moco-runner-1.5.0-standalone.jar http -p 12306 -c bar.json

Exception in thread "pool-1-thread-249" java.lang.IllegalStateException: Duplicate key Accept-Encoding
    at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)
    at java.util.HashMap.merge(HashMap.java:1255)
    at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320)
    at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at com.github.dreamhead.moco.action.ActionMonitor.asHeaders(ActionMonitor.java:61)
    at com.github.dreamhead.moco.action.ActionMonitor.postAction(ActionMonitor.java:68)
    at com.github.dreamhead.moco.action.MocoRequestAction.execute(MocoRequestAction.java:36)
    at com.github.dreamhead.moco.action.MocoAsyncAction.lambda$execute$0(MocoAsyncAction.java:25)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)

expect:

response of https://mysite-xxxxxx.com

{
    "status": "success",
    "resultCode": "success",
    "resultObject": {
        "aaa": "0",
        "bbb": "0",
        "ccc": "0",
        "ddd": "0"
    },
    "message": "",
    "traceId": "67cc63c61e124a50b167440278e137cd.540.1xxxxxxxxxx",
    "requestToken": "114051339750666666xxx"
}
comeCU commented 1 year ago

com.github.dreamhead.moco.action.ActionMonitor#asHeaders this lambda not use mergeFunction

private Map<String, String> asHeaders(final Header[] allHeaders) {
        return Arrays.stream(allHeaders)
                .collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue, (v1, v2) -> v1));
    }
comeCU commented 1 year ago

The problem has been solved, many thanks for the hard work you guys put into this project.

dreamhead commented 1 year ago

@comeCU Thank you for your locating what's wrong.