Java Code Examples for org.apache.servicecomb.foundation.common.utils.BeanUtils#getBean()

The following examples show how to use org.apache.servicecomb.foundation.common.utils.BeanUtils#getBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findExecutor_twoParam_schemaCfg_withoutOpDef(@Mocked Executor executor,
    @Mocked OperationMeta operationMeta) {
  String schemaName = "schemaId";
  String opBeanId = "opBeanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaName, opBeanId);
  new Expectations(BeanUtils.class) {
    {
      operationMeta.getSchemaId();
      result = schemaName;
      BeanUtils.getBean(opBeanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, null));
}
 
Example 2
Source File: TestExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findExecutor_twoParam_opCfg_withOpDef(@Mocked Executor executor,
    @Mocked Executor defExecutor,
    @Mocked OperationMeta operationMeta) {
  String schemaQualifiedName = "schemaId.opId";
  String opBeanId = "opBeanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaQualifiedName, opBeanId);
  new Expectations(BeanUtils.class) {
    {
      operationMeta.getSchemaQualifiedName();
      result = schemaQualifiedName;
      BeanUtils.getBean(opBeanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, defExecutor));
}
 
Example 3
Source File: TestExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void findExecutor_twoParam_opCfg_withoutOpDef(@Mocked Executor executor,
    @Mocked OperationMeta operationMeta) {
  String schemaQualifiedName = "schemaId.opId";
  String opBeanId = "opBeanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaQualifiedName, opBeanId);
  new Expectations(BeanUtils.class) {
    {
      operationMeta.getSchemaQualifiedName();
      result = schemaQualifiedName;
      BeanUtils.getBean(opBeanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, null));
}
 
Example 4
Source File: SpringInstanceFactory.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public Object create(String beanId) {
  Object instance = BeanUtils.getBean(beanId);
  if (instance == null) {
    throw new Error("Fail to find bean:" + beanId);
  }

  return instance;
}
 
Example 5
Source File: PackProviderHandler.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
public PackProviderHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaProviderHandler cannot work rightly, please make sure omegaContext is in the spring application context.\"");
  }
  this.omegaContext = context;
}
 
Example 6
Source File: PackConsumerHandler.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
public PackConsumerHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaConsumerHandler cannot work rightly, please make sure omegaContext is in the spring application context.");
  }
  this.omegaContext = context;
}
 
Example 7
Source File: TestExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void findExecutor_twoParam_defaultCfg(@Mocked Executor executor,
    @Mocked SchemaMeta schemaMeta,
    @Mocked OperationMeta operationMeta) {
  String beanId = "beanId";
  ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, beanId);
  new Expectations(BeanUtils.class) {
    {
      BeanUtils.getBean(beanId);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, null));
}
 
Example 8
Source File: TestExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void findExecutor_oneParam(@Mocked Executor executor, @Mocked OperationMeta operationMeta) {
  new Expectations(BeanUtils.class) {
    {
      BeanUtils.getBean(ExecutorManager.EXECUTOR_DEFAULT);
      result = executor;
    }
  };

  Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta));
}
 
Example 9
Source File: ExecutorManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public Executor findExecutorById(String id) {
  Executor executor = executors.get(id);
  if (executor != null) {
    return executor;
  }

  return BeanUtils.getBean(id);
}
 
Example 10
Source File: SpringmvcConsumerMain.java    From servicecomb-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  BeanUtils.init();

  SpringmvcBasicClient springmvcBasicClient = BeanUtils.getBean("SpringmvcBasicClient");
  SpringmvcHelloClient springmvcHelloClient = BeanUtils.getBean("SpringmvcHelloClient");

  long begin = System.currentTimeMillis();
  springmvcHelloClient.run();
  springmvcBasicClient.run();

  System.out.println("Spring MVC Consumer execute successfully." + (System.currentTimeMillis() - begin) );
}
 
Example 11
Source File: SpringmvcClient.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void run() throws Exception {
  testHttpClientsIsOk();
  testConfigurationDuplicate();

  templateUrlWithServiceName.setRequestFactory(new UrlWithServiceNameClientHttpRequestFactory());
  restTemplate = RestTemplateBuilder.create();
  templateUrlWithProviderPrefix.setRequestFactory(new UrlWithProviderPrefixClientHttpRequestFactory("/pojo/rest"));
  controller = BeanUtils.getBean("controller");

  String prefix = "cse://springmvc";
  String microserviceName = "springmvc";

  try {
    // this test class is intended for retry hanging issue JAV-127
    templateUrlWithServiceName.getForObject(prefix + "/controller/sayhi?name=throwexception", String.class);
    TestMgr.check("true", "false");
  } catch (Exception e) {
    TestMgr.check("true", "true");
  }

  CodeFirstRestTemplateSpringmvc codeFirstClient =
      BeanUtils.getContext().getBean(CodeFirstRestTemplateSpringmvc.class);
  codeFirstClient.testCodeFirst(restTemplate, "springmvc", "/codeFirstSpringmvc/");
  codeFirstClient.testCodeFirst(templateUrlWithProviderPrefix, "springmvc", "/pojo/rest/codeFirstSpringmvc/");

  testAllTransport(microserviceName);
  testRestTransport(microserviceName, prefix);
  CategorizedTestCaseRunner.runCategorizedTestCase(microserviceName);
}
 
Example 12
Source File: ServerApplication.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 13
Source File: ServerApplication.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 14
Source File: ServerApplication.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(ServerApplication.class).web(WebApplicationType.SERVLET).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 15
Source File: EdgeApplication.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  new SpringApplicationBuilder().sources(EdgeApplication.class).web(WebApplicationType.NONE).build().run(args);

  SelfServiceInvoker invoker = BeanUtils.getBean("SelfServiceInvoker");
  invoker.latch.await(10, TimeUnit.SECONDS);
  TestMgr.check(invoker.result, "hello");

  TestMgr.summary();
  if (!TestMgr.errors().isEmpty()) {
    System.exit(1);
  }
}
 
Example 16
Source File: SagaProviderHandler.java    From txle with Apache License 2.0 5 votes vote down vote up
public SagaProviderHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaProviderHandler cannot work rightly, please make sure omegaContext is in the spring application context.\"");
  }
  this.omegaContext = context;
}
 
Example 17
Source File: SagaConsumerHandler.java    From txle with Apache License 2.0 5 votes vote down vote up
public SagaConsumerHandler() {
  OmegaContext context = null;
  try {
    context = BeanUtils.getBean("omegaContext");
  } catch (NullPointerException npe) {
    LOG.warn("SagaConsumerHandler cannot work rightly, please make sure omegaContext is in the spring application context.");
  }
  this.omegaContext = context;
}
 
Example 18
Source File: PojoClient.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static void run() throws Exception {
  testHttpClientsIsOk();
  CategorizedTestCaseRunner.runCategorizedTestCase("pojo");

  smartcare = BeanUtils.getBean("smartcare");
  String microserviceName = "pojo";
  codeFirstPojoClient.testCodeFirst(microserviceName);

  for (String transport : DemoConst.transports) {
    ArchaiusUtils.setProperty("servicecomb.references.transport." + microserviceName, transport);
    TestMgr.setMsg(microserviceName, transport);
    LOGGER.info("test {}, transport {}", microserviceName, transport);

    testContextClassLoaderIsNull();
    testNull(testFromXml);
    testNull(test);

    // This test case shows destroy of WeightedResponseTimeRule timer task. after test finished will not print:
    // "Weight adjusting job started" and thread "NFLoadBalancer-serverWeightTimer-unknown" destroyed.
    ArchaiusUtils.setProperty("servicecomb.loadbalance.strategy.name", "WeightedResponse");
    testStringArray(test);
    ArchaiusUtils.setProperty("servicecomb.loadbalance.strategy.name", "RoundRobin");
    testStringArray(test);

    boolean checkerDestroyed = true;
    // Timer cancel may not destroy thread very fast so check for 3 times.
    for (int i = 0; i < 3; i++) {
      checkerDestroyed = true;
      Set<Thread> allThreads = Thread.getAllStackTraces().keySet();
      for (Thread t : allThreads) {
        if (t.getName().equals("NFLoadBalancer-serverWeightTimer-unknown")) {
          checkerDestroyed = false;
          Thread.sleep(1000);
        }
      }
    }
    TestMgr.check(checkerDestroyed, true);

    testChinese(test);
    testStringHaveSpace(test);
    testWrapParam(test);
    testSplitParam(test);
    testInputArray(test);

    testException(test);

    testSmartCare(smartcare);

    testCommonInvoke(transport);

    if ("rest".equals(transport)) {
      testTraceIdOnNotSetBefore();
      testNullRest(test);
      testExceptionRest(test);
      testEmptyRest(test);
    } else if ("highway".equals(transport)) {
      testNullHighway(test);
      testEmptyHighway(test);
    }

    testTraceIdOnContextContainsTraceId();
  }
}