当前位置: 首页>>代码示例>>Java>>正文


Java TestProbe类代码示例

本文整理汇总了Java中akka.testkit.TestProbe的典型用法代码示例。如果您正苦于以下问题:Java TestProbe类的具体用法?Java TestProbe怎么用?Java TestProbe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TestProbe类属于akka.testkit包,在下文中一共展示了TestProbe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import akka.testkit.TestProbe; //导入依赖的package包/类
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    doNothing().when(mockCallback).accept(any(MockFailure.class));

    ticker = new FakeTicker();
    ticker.advance(ThreadLocalRandom.current().nextLong());
    doReturn(ticker).when(mockContext).ticker();

    final ClientActorConfig mockConfig = AccessClientUtil.newMockClientActorConfig();
    doReturn(mockConfig).when(mockContext).config();

    doReturn(mock(MessageSlicer.class)).when(mockContext).messageSlicer();

    mockActor = TestProbe.apply(actorSystem);
    mockBackendInfo = new BackendInfo(mockActor.ref(), 0, ABIVersion.current(), 5);
    mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
    mockRequest2 = new MockRequest(mockIdentifier, mockReplyTo);
    mockResponse = mockRequest.toRequestFailure(mockCause);
    mockResponseEnvelope = new FailureEnvelope(mockResponse, 0, 0, 0);
    mockCookie = ThreadLocalRandom.current().nextLong();

    queue = new ConnectingClientConnection<>(mockContext, mockCookie);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:ConnectingClientConnectionTest.java

示例2: applyModifyTransactionRequest

import akka.testkit.TestProbe; //导入依赖的package包/类
private void applyModifyTransactionRequest(final boolean coordinated) {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder =
            new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    final TransactionModification write = new TransactionWrite(PATH_1, DATA_1);
    final TransactionModification merge = new TransactionMerge(PATH_2, DATA_2);
    final TransactionModification delete = new TransactionDelete(PATH_3);
    builder.addModification(write);
    builder.addModification(merge);
    builder.addModification(delete);
    builder.setSequence(0L);
    builder.setCommit(coordinated);
    final ModifyTransactionRequest request = builder.build();
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    transaction.replayModifyTransactionRequest(request, callback, Ticker.systemTicker().read());
    verify(modification).write(PATH_1, DATA_1);
    verify(modification).merge(PATH_2, DATA_2);
    verify(modification).delete(PATH_3);
    final CommitLocalTransactionRequest commitRequest =
            getTester().expectTransactionRequest(CommitLocalTransactionRequest.class);
    Assert.assertEquals(modification, commitRequest.getModification());
    Assert.assertEquals(coordinated, commitRequest.isCoordinated());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:LocalReadWriteProxyTransactionTest.java

示例3: testHandleForwardedRemoteExistsRequest

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void testHandleForwardedRemoteExistsRequest() throws Exception {
    final TestProbe probe = createProbe();
    final ExistsTransactionRequest request =
            new ExistsTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, true);
    final Consumer<Response<?, ?>> callback = createCallbackMock();
    setupExecuteInActor();

    transaction.handleReplayedRemoteRequest(request, callback, Ticker.systemTicker().read());
    final ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(callback).accept(captor.capture());
    final Response<?, ?> value = captor.getValue();
    Assert.assertTrue(value instanceof ExistsTransactionSuccess);
    final ExistsTransactionSuccess success = (ExistsTransactionSuccess) value;
    Assert.assertTrue(success.getExists());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:LocalProxyTransactionTest.java

示例4: testSerialization

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void testSerialization() {
    byte[] data = new byte[1000];
    for (int i = 0, j = 0; i < data.length; i++) {
        data[i] = (byte)j;
        if (++j >= 255) {
            j = 0;
        }
    }

    MessageSlice expected = new MessageSlice(new StringIdentifier("test"), data, 2, 3, 54321,
            TestProbe.apply(actorSystem).ref());
    MessageSlice cloned = (MessageSlice) SerializationUtils.clone(expected);

    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
    assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
    assertEquals("getTotalSlices", expected.getTotalSlices(), cloned.getTotalSlices());
    assertEquals("getLastSliceHashCode", expected.getLastSliceHashCode(), cloned.getLastSliceHashCode());
    assertArrayEquals("getData", expected.getData(), cloned.getData());
    assertEquals("getReplyTo", expected.getReplyTo(), cloned.getReplyTo());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:MessageSliceTest.java

示例5: setUp

import akka.testkit.TestProbe; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    clientContextProbe = new TestProbe(system, "clientContext");
    backendProbe = new TestProbe(system, "backend");
    context = AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID,
            PERSISTENCE_ID);
    final ShardBackendInfo backend = new ShardBackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON,
            "default", UnsignedLong.ZERO, Optional.empty(), 3);
    final AbstractClientConnection<ShardBackendInfo> connection =
            AccessClientUtil.createConnectedConnection(context, 0L, backend);
    final ProxyHistory parent = ProxyHistory.createClient(history, connection, HISTORY_ID);
    transaction = createTransaction(parent, TestUtils.TRANSACTION_ID, snapshot);
    tester = new TransactionTester<>(transaction, connection, backendProbe);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:AbstractProxyTransactionTest.java

示例6: testRefreshBackendInfo

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void testRefreshBackendInfo() throws Exception {
    final CompletionStage<ShardBackendInfo> backendInfo = moduleShardBackendResolver.getBackendInfo(0L);
    //handle first connect
    contextProbe.expectMsgClass(ConnectClientRequest.class);
    final TestProbe staleBackendProbe = new TestProbe(system, "staleBackend");
    final ConnectClientSuccess msg = new ConnectClientSuccess(CLIENT_ID, 0L, staleBackendProbe.ref(),
            Collections.emptyList(), dataTree, 3);
    contextProbe.reply(msg);
    //get backend info
    final ShardBackendInfo staleBackendInfo = TestUtils.getWithTimeout(backendInfo.toCompletableFuture());
    //refresh
    final CompletionStage<ShardBackendInfo> refreshed =
            moduleShardBackendResolver.refreshBackendInfo(0L, staleBackendInfo);
    //stale backend info should be removed and new connect request issued to the context
    contextProbe.expectMsgClass(ConnectClientRequest.class);
    final TestProbe refreshedBackendProbe = new TestProbe(system, "refreshedBackend");
    final ConnectClientSuccess msg2 = new ConnectClientSuccess(CLIENT_ID, 1L, refreshedBackendProbe.ref(),
            Collections.emptyList(), dataTree, 3);
    contextProbe.reply(msg2);
    final ShardBackendInfo refreshedBackendInfo = TestUtils.getWithTimeout(refreshed.toCompletableFuture());
    Assert.assertEquals(staleBackendInfo.getCookie(), refreshedBackendInfo.getCookie());
    Assert.assertEquals(refreshedBackendProbe.ref(), refreshedBackendInfo.getActor());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:25,代码来源:ModuleShardBackendResolverTest.java

示例7: setUp

import akka.testkit.TestProbe; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    final TestProbe clientContextProbe = new TestProbe(system, "clientContext");
    final ClientActorContext context =
            AccessClientUtil.createClientActorContext(system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    transactions = new ArrayList<>();
    for (int i = 0; i < TRANSACTIONS; i++) {
        transactions.add(createTransactionTester(new TestProbe(system, "backend" + i), context, history));
    }
    final Collection<AbstractProxyTransaction> proxies = transactions.stream()
            .map(TransactionTester::getTransaction)
            .collect(Collectors.toList());
    proxies.forEach(AbstractProxyTransaction::seal);
    cohort = new ClientTransactionCommitCohort(history, TRANSACTION_ID, proxies);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:ClientTransactionCommitCohortTest.java

示例8: expectActor

import akka.testkit.TestProbe; //导入依赖的package包/类
public ActorRef expectActor(JavaTestKit kit, String path) {
    final ActorRef[] actor = {null};
    kit.new AwaitCond(kit.duration("3 seconds"), kit.duration("150 millis"), "No actor found with " + path) {
        @Override
        protected boolean cond() {
            TestProbe probe = new TestProbe(system);
            system.actorSelection(path).tell(new akka.actor.Identify(101), probe.ref());
            ActorIdentity i = probe.expectMsgClass(kit.duration("100 millis"), ActorIdentity.class);
            actor[0] = i.getRef();
            return i.getRef() != null;
        }
    };
    return actor[0];
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:15,代码来源:BaseAkkaTestCase.java

示例9: sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse() {
    new JavaTestKit(system) {{
        ActorRef coffeeHouse = getRef();
        TestProbe guest = new TestProbe(system);
        ActorRef waiter = system.actorOf(Waiter.props(coffeeHouse, system.deadLetters(), Integer.MAX_VALUE));
        waiter.tell(new Waiter.ServeCoffee(new Coffee.Akkaccino()), guest.ref());
        expectMsgEquals(new CoffeeHouse.ApproveCoffee(new Coffee.Akkaccino(), guest.ref()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:11,代码来源:WaiterTest.java

示例10: sendingComplaintShouldResultInPrepareCoffeeToBarista

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void sendingComplaintShouldResultInPrepareCoffeeToBarista() {
    new JavaTestKit(system) {{
        ActorRef barista = getRef();
        TestProbe guest = new TestProbe(system);
        ActorRef waiter = system.actorOf(Waiter.props(system.deadLetters(), barista, 1));

        waiter.tell(new Waiter.Complaint(new Coffee.Akkaccino()), guest.ref());
        expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), guest.ref()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:12,代码来源:WaiterTest.java

示例11: sendingServeCoffeeShouldResultInPrepareCoffeeToBarista

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void sendingServeCoffeeShouldResultInPrepareCoffeeToBarista() {
    new JavaTestKit(system) {{
        ActorRef barista = getRef();
        TestProbe guest = new TestProbe(system);
        ActorRef waiter = system.actorOf(Waiter.props(barista));
        waiter.tell(new Waiter.ServeCoffee(new Coffee.Akkaccino()), guest.ref());
        expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), guest.ref()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:11,代码来源:WaiterTest.java

示例12: testForwardToRemoteCommit

import akka.testkit.TestProbe; //导入依赖的package包/类
@Override
@Test
public void testForwardToRemoteCommit() throws Exception {
    final TestProbe probe = createProbe();
    final CursorAwareDataTreeModification modification = mock(CursorAwareDataTreeModification.class);
    final CommitLocalTransactionRequest request =
            new CommitLocalTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), modification, null, true);
    doAnswer(LocalProxyTransactionTest::applyToCursorAnswer).when(modification).applyToCursor(any());
    final ModifyTransactionRequest modifyRequest = testForwardToRemote(request, ModifyTransactionRequest.class);
    verify(modification).applyToCursor(any());
    Assert.assertTrue(modifyRequest.getPersistenceProtocol().isPresent());
    Assert.assertEquals(PersistenceProtocol.THREE_PHASE, modifyRequest.getPersistenceProtocol().get());
    checkModifications(modifyRequest);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:15,代码来源:LocalProxyTransactionTest.java

示例13: sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse() {
    new JavaTestKit(system) {{
        ActorRef coffeeHouse = getRef();
        TestProbe guest = new TestProbe(system);
        ActorRef waiter = system.actorOf(Waiter.props(coffeeHouse));
        waiter.tell(new Waiter.ServeCoffee(new Coffee.Akkaccino()), guest.ref());
        expectMsgEquals(new CoffeeHouse.ApproveCoffee(new Coffee.Akkaccino(), guest.ref()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:11,代码来源:WaiterTest.java

示例14: testForwardToRemoteModifyExists

import akka.testkit.TestProbe; //导入依赖的package包/类
@Test
public void testForwardToRemoteModifyExists() throws Exception {
    final TestProbe probe = createProbe();
    final ExistsTransactionRequest request =
            new ExistsTransactionRequest(TRANSACTION_ID, 0L, probe.ref(), PATH_1, false);
    final ExistsTransactionRequest received = testForwardToRemote(request, ExistsTransactionRequest.class);
    Assert.assertEquals(request.getTarget(), received.getTarget());
    Assert.assertEquals(request.getPath(), received.getPath());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:RemoteProxyTransactionTest.java

示例15: testSuccess

import akka.testkit.TestProbe; //导入依赖的package包/类
private void testSuccess() {
    MessageSliceReply expected = MessageSliceReply.success(new StringIdentifier("test"), 3,
            TestProbe.apply(actorSystem).ref());
    MessageSliceReply cloned = (MessageSliceReply) SerializationUtils.clone(expected);

    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
    assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
    assertEquals("getSendTo", expected.getSendTo(), cloned.getSendTo());
    assertEquals("getFailure present", Boolean.FALSE, cloned.getFailure().isPresent());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:11,代码来源:MessageSliceReplyTest.java


注:本文中的akka.testkit.TestProbe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。