小编Kha*_*hah的帖子

使用 SLF4J 的堆栈驱动程序日志记录未在 Scala 中正确记录

我正在使用 Logback 和 SLF4J 进行 Stackdriver 日志记录,并且我正在遵循Google Cloud 中的示例。我的应用程序是用 Scala 编写的,并在 GCP 上的 Dataproc 集群上运行。

logback.xml 有以下内容。

<configuration>
  <appender name="CLOUD" class="com.google.cloud.logging.logback.LoggingAppender">
    <!-- Optional : filter logs at or above a level -->
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>INFO</level>
    </filter>
    <log>application.log</log> <!-- Optional : default java.log -->
    <resourceType>gae_app</resourceType> <!-- Optional : default: auto-detected, fallback: global -->
    <enhancer>com.company.customer.utils.MyLoggingEnhancer</enhancer> <!-- Optional -->
    <flushLevel>WARN</flushLevel> <!-- Optional : default ERROR -->
  </appender>

  <root level="info">
    <appender-ref ref="CLOUD" />
  </root>
</configuration>
Run Code Online (Sandbox Code Playgroud)

和 MyLoggingEnhancer 是

package com.company.customer.utils

import com.google.cloud.logging.LogEntry.Builder …
Run Code Online (Sandbox Code Playgroud)

scala slf4j google-cloud-platform google-cloud-logging google-cloud-stackdriver

6
推荐指数
0
解决办法
900
查看次数

当Camel从XML文件加载路由时,在注册表中找不到Bean

我在camel中遇到问题,在运行时从XML加载路由.我搜索了我的问题并在以下网址找到了相关的讨论:http://grokbase.com/p/camel/users/117w8m6rbm/injecting-data-to-routes-loaded-from-xml-file.

我的问题有点不同.我想运行下面给出的那条路线.

<routes xmlns="http://camel.apache.org/schema/spring">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd" >
<bean id="myDb" class="com.mongodb.MongoClient">
<constructor-arg name="host" value="localhost" />
    <constructor-arg name="port" value="27017" />
</bean>
<bean id="mongodb" class="org.apache.camel.component.mongodb.MongoDbComponent"></bean>
</beans>
<route id="_route1">
        <description>here is a sample which subscribe data( proper json object) from mqtt topic  from broker and push into Mongo Db</description>
        <from id="_from1" uri="paho:iot/test/#?brokerUrl=tcp://localhost:1883"/>
        <to id="_to2" uri="mongodb:myDb?database=Volt&amp;collection=dummyData&amp;operation=insert"/>
</route>
</routes>
Run Code Online (Sandbox Code Playgroud)

它给了我例外:

14:14:58.249 INFO  c.v.integration.route.CustomRouter - Exception {}
org.apache.camel.FailedToCreateRouteException: Failed to create route _route1: Route(_route1)[[From[paho:iot/test/#?brokerUrl=tcp://localho... because of …
Run Code Online (Sandbox Code Playgroud)

java xml spring apache-camel mongodb

5
推荐指数
1
解决办法
1358
查看次数

PowerMock:模拟具有不同参数的同一方法的多个调用行为异常

我是Mockito的新手,遇到一个问题占用了我很多时间。以下是我的问题说明和可执行代码。

问题

每当我尝试使用不同的参数模拟来自同一方法的多种行为时,mockito / powermockito使用我在单个测试中为测试定义的最后一个行为。以下是我的示例,Service类具有foo从我的方法中调用的静态方法(即要测试)使用不同参数的次数。

它抛出ClassCastException,想投BResponseAResponse,因为我最后磕碰如果BResponse,而我的第一个呼吁fooClassUnderTest.execute()需求AResponse

样例代码

package poc.staticmethod;

import static org.mockito.Matchers.any;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import lombok.AllArgsConstructor;
import lombok.Data;

@RunWith(PowerMockRunner.class)
@PrepareForTest(PocStaticTest.Service.class)
public class PocStaticTest {


  @InjectMocks
  ClassUnderTest c = new ClassUnderTest();

  @Before
  public void beforeTest() throws Exception {
    mockStatic(Service.class);
  }

  @Test
  public void myTest() {
    when(Service.foo(any(), new …
Run Code Online (Sandbox Code Playgroud)

java mockito powermock powermockito

3
推荐指数
1
解决办法
2184
查看次数

从微秒以微秒的精度以字符串格式创建实际日期

我想从微秒创建一个 java.util.Date 对象。但我不想失去它的精度微秒到毫秒。目前我正在通过以下方式将微秒转换为 Date 对象。如果我将微秒传递给 Date 构造函数,那么它会给出一个错误的日期,例如56521-12-01.

long microSeconds = value.getTimestampValue();// This function returns a microseconds.
DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS);
long millis = TimeUnit.MILLISECONDS.convert(microSeconds, TimeUnit.MICROSECONDS);
String startDate = FORMAT.format(new Date(millis));
Run Code Online (Sandbox Code Playgroud)

我不想将微秒转换为毫秒。是否有 API 或 java-8 实用程序的方法可以将微秒直接转换为 Date 对象?

这种方法的问题是它删除微秒的最后三位数字使其成为毫秒,然后从毫秒创建一个日期对象,解析器只需将其毫秒部分乘以将其1000转换为微秒。通过这种方式,我丢失了一个实际的微发送。

java java.util.date java-8

0
推荐指数
2
解决办法
2373
查看次数