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


Java TestKit类代码示例

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


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

示例1: searchCourseOnReceiveTest

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void searchCourseOnReceiveTest() {

    TestKit probe = new TestKit(system);
    ActorRef subject = system.actorOf(props);

    Request reqObj = new Request();
    reqObj.setOperation(ActorOperations.SEARCH_COURSE.getValue());
    HashMap<String, Object> innerMap = new HashMap<>();
    innerMap.put(JsonKey.QUERY, "NTP course");
    Map<String, Object> map = new HashMap<>();
    List<String> fields = new ArrayList<String>();
    fields.add("noOfLecture");
    innerMap.put(JsonKey.FIELDS , fields);
    map.put(JsonKey.SEARCH, innerMap);
    reqObj.setRequest(map);
    subject.tell(reqObj, probe.getRef());
    Response res = probe.expectMsgClass(Response.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:20,代码来源:CourseSearchActorTest.java

示例2: test9DeleteNoteException

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
/**
 * Method to test delete Note when data is invalid.
 * Expected to throw exception
 */
@SuppressWarnings("deprecation")
@Test
public void test9DeleteNoteException(){
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);

  Request actorMessage = new Request();
  Map<String,Object> request = new HashMap<>();
  request.put(JsonKey.REQUESTED_BY , userId);
  request.put(JsonKey.NOTE_ID , noteId+"invalid");
  actorMessage.setRequest(request);
  actorMessage.setOperation(ActorOperations.DELETE_NOTE.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException res= probe.expectMsgClass(duration("10 second"),ProjectCommonException.class);
  if(null != res){
    Assert.assertEquals("You are not authorized.", res.getMessage());
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:24,代码来源:NotesManagementActorTest.java

示例3: killAllOnCompensationComplete

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void killAllOnCompensationComplete() throws Exception {
  new TestKit(actorSystem) {{
    CompletableFuture<SagaResponse> future = new CompletableFuture<>();

    ActorRef actor = actorSystem.actorOf(CompletionCallbackActor.props(future));

    actor.tell(context, noSender());
    actor.tell(new CompensateMessage(response), noSender());

    await().atMost(2, TimeUnit.SECONDS)
        .until(() -> actor1.isTerminated() && actor2.isTerminated() && actor.isTerminated());

    assertThat(future.get(), is(response));
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:17,代码来源:CompletionCallbackActorTest.java

示例4: Z18TestJoinUserOrganisation4

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void Z18TestJoinUserOrganisation4(){
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.JOIN_USER_ORGANISATION.getValue());
  Map<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USER_ID,null);
  innerMap.put(JsonKey.ORGANISATION_ID,null);
  reqObj.getRequest().put(JsonKey.REQUESTED_BY,userIdnew);
  Map<String, Object> request = new HashMap<String, Object>();
  request.put(JsonKey.USER_ORG, innerMap);
  reqObj.setRequest(request);
  subject.tell(reqObj, probe.getRef());
  probe.expectMsgClass(duration("200 second"), ProjectCommonException.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:17,代码来源:UserManagementActorTest.java

示例5: testabAddSkillAgain

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void testabAddSkillAgain(){

  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.REQUESTED_BY , USER_ID);
  actorMessage.put(JsonKey.ENDORSED_USER_ID , ENDORSED_USER_ID);
  actorMessage.put(JsonKey.SKILL_NAME, skillsList);
  actorMessage.setOperation(ActorOperations.ADD_SKILL.getValue());

  subject.tell(actorMessage, probe.getRef());
  Response res= probe.expectMsgClass(duration("100 second"),Response.class);

}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:17,代码来源:SkillmanagementActorTest.java

示例6: TestACreateUserWithInvalidOrgId

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void TestACreateUserWithInvalidOrgId() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);

  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.CREATE_USER.getValue());
  Map<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USERNAME, "sunbird_dummy_user_212121");
  innerMap.put(JsonKey.EMAIL, "[email protected]");
  innerMap.put(JsonKey.PASSWORD, "password");
  innerMap.put(JsonKey.PROVIDER, "BLR");
  innerMap.put(JsonKey.PHONE, "9874561230");
  innerMap.put(JsonKey.PHONE_VERIFIED, true);
  innerMap.put(JsonKey.EMAIL_VERIFIED, true);
  innerMap.put(JsonKey.REGISTERED_ORG_ID, (orgId+"13215665"));
  
  Map<String, Object> request = new HashMap<String, Object>();
  request.put(JsonKey.USER, innerMap);
  reqObj.setRequest(request);

  subject.tell(reqObj, probe.getRef());
  probe.expectMsgClass(duration("200 second"), ProjectCommonException.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:25,代码来源:UserManagementActorTest.java

示例7: Z17TestAssignRolesWithoutOrgId

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void Z17TestAssignRolesWithoutOrgId(){
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.ASSIGN_ROLES.getValue());
  Map<String, Object> request = new HashMap<String, Object>();
  request.put(JsonKey.USERNAME,"sunbird_dummy_user_212121");
  request.put(JsonKey.EXTERNAL_ID, "EXT_ID_DUMMY");
  request.put(JsonKey.PROVIDER, "BLR");
  List<String> roles = new ArrayList<>();
  roles.add("CONTENT_REVIEWER");
  request.put(JsonKey.ROLES, roles);
  reqObj.setRequest(request);
  subject.tell(reqObj, probe.getRef());
  probe.expectMsgClass(duration("200 second"), Response.class);
  Map<String,Object> map = ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(), ProjectUtil.EsType.user.getTypeName(), userId);
  System.out.println("Login Id "+map.get(JsonKey.LOGIN_ID));
  List<Map<String,Object>> usrOrgList = (List<Map<String, Object>>) map.get(JsonKey.ORGANISATIONS);
  for(Map<String,Object> usrOrg : usrOrgList){
    if(orgId.equalsIgnoreCase((String)usrOrg.get(JsonKey.ID))){
      assertTrue(((List<String>)map.get(JsonKey.ROLES)).contains("CONTENT_REVIEWER"));
    }
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:26,代码来源:UserManagementActorTest.java

示例8: testA1CreateBatchWithInvalidCourseId

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
public void testA1CreateBatchWithInvalidCourseId(){
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.CREATE_BATCH.getValue());
  HashMap<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.COURSE_ID, "12345");
  innerMap.put(JsonKey.NAME, "DUMMY_COURSE_NAME1");
  innerMap.put(JsonKey.ENROLLMENT_TYPE, "invite-only");
  innerMap.put(JsonKey.START_DATE , (String)format.format(new Date()));
  innerMap.put(JsonKey.HASHTAGID ,hashTagId );
  Calendar now =  Calendar.getInstance();
  now.add(Calendar.DAY_OF_MONTH, 5);
  Date after5Days = now.getTime();
  innerMap.put(JsonKey.END_DATE , (String)format.format(after5Days));
  reqObj.getRequest().put(JsonKey.BATCH, innerMap);
  subject.tell(reqObj, probe.getRef());
  probe.expectMsgClass(duration("1000 second"),ProjectCommonException.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:20,代码来源:CourseBatchManagementActorTest.java

示例9: tellNodeResponseToAllChildren

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void tellNodeResponseToAllChildren() throws Exception {
  new TestKit(actorSystem) {{
    addChildren(getRef());

    ActorRef parent = someActor();
    context.addParent(requestId, parent);

    when(request.parents()).thenReturn(new String[] {parentRequestId1});
    when(task.commit(request, Operation.SUCCESSFUL_SAGA_RESPONSE)).thenReturn(response);

    ActorRef actorRef = actorSystem.actorOf(RequestActor.props(context, task, request));

    actorRef.tell(new TransactMessage(request1, Operation.SUCCESSFUL_SAGA_RESPONSE), parent);

    List<SagaResponse> responses = receiveN(2, duration("2 seconds")).stream()
        .map(o -> ((TransactMessage) o).response())
        .collect(Collectors.toList());

    assertThat(responses, containsInAnyOrder(response, response));

    verify(task).commit(request, Operation.SUCCESSFUL_SAGA_RESPONSE);
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:25,代码来源:RequestActorTest.java

示例10: tellAllRelativesToAbortOnError

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void tellAllRelativesToAbortOnError() throws Exception {
  new TestKit(actorSystem) {{
    context.addChild(requestId, getRef());
    context.addActor(requestId, getRef());

    context.addParent(requestId, getRef());

    when(request.parents()).thenReturn(new String[] {parentRequestId1});
    when(task.commit(request, Operation.SUCCESSFUL_SAGA_RESPONSE)).thenThrow(exception);

    ActorRef actorRef = actorSystem.actorOf(RequestActor.props(context, task, request));

    actorRef.tell(new TransactMessage(request1, Operation.SUCCESSFUL_SAGA_RESPONSE), getRef());

    List<SagaResponse> responses = receiveN(2, duration("2 seconds")).stream()
        .map(o -> ((AbortMessage) o).response())
        .collect(Collectors.toList());

    assertThat(responses, containsInAnyOrder(instanceOf(FailedSagaResponse.class), instanceOf(FailedSagaResponse.class)));
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:23,代码来源:RequestActorTest.java

示例11: tellAllRelativesExceptSenderToAbortOnAbort

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void tellAllRelativesExceptSenderToAbortOnAbort() throws Exception {
  new TestKit(actorSystem) {{
    context.addChild(requestId, getRef());
    context.addActor(requestId, getRef());

    context.addParent(requestId, getRef());

    when(request.parents()).thenReturn(new String[] {parentRequestId1});

    ActorRef actorRef = actorSystem.actorOf(RequestActor.props(context, task, request));

    actorRef.tell(new AbortMessage(exception), someActor());

    List<SagaResponse> responses = receiveN(2, duration("2 seconds")).stream()
        .map(o -> ((AbortMessage) o).response())
        .collect(Collectors.toList());

    assertThat(responses, containsInAnyOrder(instanceOf(FailedSagaResponse.class), instanceOf(FailedSagaResponse.class)));

    actorRef.tell(new AbortMessage(exception), someActor());
    expectNoMsg(duration("500 milliseconds"));
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:25,代码来源:RequestActorTest.java

示例12: doNotCompensateIfTransactionIsNotCompleted

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void doNotCompensateIfTransactionIsNotCompleted() throws Exception {
  new TestKit(actorSystem) {{
    addChildren(someActor());
    context.addParent(requestId, getRef());

    when(request.parents()).thenReturn(new String[] {parentRequestId1});

    ActorRef actorRef = actorSystem.actorOf(RequestActor.props(context, task, request));

    actorRef.tell(new AbortMessage(exception), noSender());
    actorRef.tell(compensateMessage, getRef());
    actorRef.tell(compensateMessage, getRef());

    List<Object> responses = receiveN(2, duration("2 seconds"));
    assertThat(responses, contains(instanceOf(AbortMessage.class), instanceOf(CompensateMessage.class)));
    verify(task, never()).compensate(request);

    // no duplicate compensation
    reset(task);
    actorRef.tell(compensateMessage, getRef());
    actorRef.tell(compensateMessage, getRef());
    expectNoMsg(duration("200 milliseconds"));
    verify(task, never()).compensate(request);
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:27,代码来源:RequestActorTest.java

示例13: tellTransactionResponseToChildrenOnRecovery

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void tellTransactionResponseToChildrenOnRecovery() throws Exception {
  new TestKit(actorSystem) {{
    context.addChild(requestId, getRef());

    ActorRef parent = someActor();
    context.addParent(requestId, parent);

    when(request.parents()).thenReturn(new String[] {parentRequestId1});

    ActorRef actorRef = actorSystem.actorOf(RequestActor.props(context, task, request));

    actorRef.tell(new TransactionRecoveryMessage(response), noSender());
    actorRef.tell(new TransactMessage(request1, Operation.SUCCESSFUL_SAGA_RESPONSE), parent);

    List<SagaResponse> responses = receiveN(1, duration("2 seconds")).stream()
        .map(o -> ((TransactMessage) o).response())
        .collect(Collectors.toList());

    assertThat(responses, containsInAnyOrder(response));

    verify(task, never()).commit(request, Operation.SUCCESSFUL_SAGA_RESPONSE);
  }};
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:25,代码来源:RequestActorTest.java

示例14: testCreateTanentPreferenceWithInvalidOrgId

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void testCreateTanentPreferenceWithInvalidOrgId(){

  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request actorMessage = new Request();
  List<Map<String , Object>> reqList = new ArrayList<>();

  Map<String , Object> map = new HashMap<>();
  map.put(JsonKey.ROLE , "admin");
  reqList.add(map);

  actorMessage.getRequest().put(JsonKey.TENANT_PREFERENCE , reqList);
  actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID , "");
  actorMessage.getRequest().put(JsonKey.REQUESTED_BY , USER_ID);
  actorMessage.setOperation(ActorOperations.CREATE_TENANT_PREFERENCE.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException res= probe.expectMsgClass(duration("100 second"),ProjectCommonException.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:21,代码来源:TenantPreferenceManagementActorTest.java

示例15: Z18TestJoinUserOrganisation3

import akka.testkit.javadsl.TestKit; //导入依赖的package包/类
@Test
public void Z18TestJoinUserOrganisation3(){
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.JOIN_USER_ORGANISATION.getValue());
  Map<String, Object> innerMap = new HashMap<>();
  innerMap.put(JsonKey.USER_ID,userId);
  innerMap.put(JsonKey.ORGANISATION_ID,(orgId2+"456as"));
  reqObj.getRequest().put(JsonKey.REQUESTED_BY,userIdnew);
  Map<String, Object> request = new HashMap<String, Object>();
  request.put(JsonKey.USER_ORG, innerMap);
  reqObj.setRequest(request);
  subject.tell(reqObj, probe.getRef());
  probe.expectMsgClass(duration("200 second"), ProjectCommonException.class);
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-mw,代码行数:17,代码来源:UserManagementActorTest.java


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