WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
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
package tech.powerjob.remote.http;
 
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import tech.powerjob.common.enums.Protocol;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.remote.framework.BenchmarkActor;
import tech.powerjob.remote.framework.base.Address;
import tech.powerjob.remote.framework.base.HandlerLocation;
import tech.powerjob.remote.framework.base.URL;
import tech.powerjob.remote.framework.engine.EngineConfig;
import tech.powerjob.remote.framework.engine.EngineOutput;
import tech.powerjob.remote.framework.engine.RemoteEngine;
import tech.powerjob.remote.framework.engine.impl.PowerJobRemoteEngine;
import tech.powerjob.remote.framework.transporter.Transporter;
 
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
 
/**
 * HttpVertxCSInitializerTest
 *
 * @author tjq
 * @since 2023/1/2
 */
@Slf4j
class HttpVertxCSInitializerTest {
 
    @Test
    void testHttpVertxCSInitializerTest() throws Exception {
 
        final Address address = new Address().setPort(7890).setHost("127.0.0.1");
 
        EngineConfig engineConfig = new EngineConfig()
                .setType(Protocol.HTTP.name())
                .setBindAddress(address)
                .setActorList(Lists.newArrayList(new BenchmarkActor()));
 
        RemoteEngine engine = new PowerJobRemoteEngine();
        EngineOutput engineOutput = engine.start(engineConfig);
        log.info("[HttpVertxCSInitializerTest] engine start up successfully!");
        Transporter transporter = engineOutput.getTransporter();
 
        BenchmarkActor.BenchmarkRequest request = new BenchmarkActor.BenchmarkRequest()
                .setContent("request from test")
                .setBlockingMills(100)
                .setResponseSize(10240);
 
        log.info("[HttpVertxCSInitializerTest] test empty request!");
        URL emptyURL = new URL()
                .setAddress(address)
                .setLocation(new HandlerLocation().setMethodPath("emptyReturn").setRootPath("benchmark"));
        transporter.tell(emptyURL, request);
 
        log.info("[HttpVertxCSInitializerTest] test string request!");
        URL stringURL = new URL()
                .setAddress(address)
                .setLocation(new HandlerLocation().setMethodPath("stringReturn").setRootPath("benchmark"));
        final String strResponse = transporter.ask(stringURL, request, String.class).toCompletableFuture().get();
        log.info("[HttpVertxCSInitializerTest] strResponse: {}", strResponse);
 
        log.info("[HttpVertxCSInitializerTest] test normal request!");
        URL url = new URL()
                .setAddress(address)
                .setLocation(new HandlerLocation().setMethodPath("standard").setRootPath("benchmark"));
 
        final CompletionStage<BenchmarkActor.BenchmarkResponse> benchmarkResponseCompletionStage = transporter.ask(url, request, BenchmarkActor.BenchmarkResponse.class);
        final BenchmarkActor.BenchmarkResponse response = benchmarkResponseCompletionStage.toCompletableFuture().get(10, TimeUnit.SECONDS);
        log.info("[HttpVertxCSInitializerTest] response: {}", response);
 
 
 
 
        CommonUtils.easySleep(10000);
    }
}