小编Pio*_*ski的帖子

如何更改主题的起始偏移量?

可以更改新主题的起始偏移量吗?我想创建一个新主题并开始从偏移量中读取10000.怎么样?

apache-kafka

19
推荐指数
4
解决办法
3万
查看次数

Spock抛出异常测试

我用Spock测试Java代码.我测试这段代码:

 try {
    Set<String> availableActions = getSthAction()
    List<String> goodActions = getGoodAction()
    if (!CollectionUtils.containsAny(availableActions ,goodActions )){
       throw new CustomException();
    }
} catch (AnotherCustomExceptio e) {
     throw new CustomException(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

我写了测试:

def "some test"() {
    given:
    bean.methodName(_) >> {throw new AnotherCustomExceptio ("Sth wrong")}
    def order = new Order();
    when:
    validator.validate(order )
    then:
    final CustomException exception = thrown()
}
Run Code Online (Sandbox Code Playgroud)

它失败了,因为AnotherCustomExceptio抛出了.但在try{}catch块中我捕获此异常并抛出一个CustomException所以我期望我的方法将抛出CustomException而不是AnotherCustomExceptio.我该如何测试?

java groovy unit-testing spock

16
推荐指数
3
解决办法
3万
查看次数

打开文件太多,同时确保索引mongo

我想在mongo集合上创建文本索引.我写

db.test1.ensureIndex({'text':'text'})
Run Code Online (Sandbox Code Playgroud)

然后我在mongod过程中看到了

Sun Jan  5 10:08:47.289 [conn1] build index library.test1 { _fts: "text", _ftsx: 1 }
Sun Jan  5 10:09:00.220 [conn1]         Index: (1/3) External Sort Progress: 200/980    20%
Sun Jan  5 10:09:13.603 [conn1]         Index: (1/3) External Sort Progress: 400/980    40%
Sun Jan  5 10:09:26.745 [conn1]         Index: (1/3) External Sort Progress: 600/980    61%
Sun Jan  5 10:09:37.809 [conn1]         Index: (1/3) External Sort Progress: 800/980    81%
Sun Jan  5 10:09:49.344 [conn1]      external sort used : 5547 files  in 62 secs
Sun …
Run Code Online (Sandbox Code Playgroud)

database macos full-text-search mongodb nosql

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

使用mapstruct映射嵌套对象

我创建如下的映射.如何将平面对象属性(如街道,城市等)映射到域对象中的嵌套地址.当我尝试我有一个错误:

[ERROR]诊断:返回类型中的未知属性"address.postalCode".@Mapping(source ="city",target ="address.city"),

@Mapper(componentModel = "spring", uses = {})
public interface CompanyMapper {
    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "street", target = "address.street"),
            @Mapping(source = "city", target = "address.city"),
            @Mapping(source = "postalCode", target = "address.postalCode"),
            @Mapping(source = "province", target = "address.province"),
    })
    DomainObject map(DtoObject dto);
Run Code Online (Sandbox Code Playgroud)

和班级......

public class Address {
            private String street;
            private Integer streetNumber;
            private String city;
            private String postalCode;
            private String province;
            //getters and setters
    }
public class DomainObject {
        private String id; …
Run Code Online (Sandbox Code Playgroud)

java spring mapstruct

7
推荐指数
1
解决办法
9584
查看次数

BigDecimal在肥皂信息中有科学记数法

我的网络服务有一个奇怪的问题.我有对象OrderPosition有一个价格(xsd:decimal,fractionDigits = 9).Apache CXF为我生成代理类,这个字段是BigDecimal.当我想发送大于10000000.00000的值时,soap消息中的这个字段有科学记数法(例如1.1423E + 7).

如何强制该值未以科学记数法发送.

java xsd soap web-services

6
推荐指数
1
解决办法
3992
查看次数

SpringMVC 400错误请求JSON数据

我向spring mvc控制器发送请求时遇到了一些问题.我有实体:

public class Person {
    private String name;
    private int age;
    private String city;
    //..getters setters

}
Run Code Online (Sandbox Code Playgroud)

和SpringMvc控制器:

@Controller
@RequestMapping("/companies")
public class FirmaController {
    @RequestMapping(value = "/addPerson", method = RequestMethod.POST, headers = {"Content-type=application/json"})
    public String addPerson(@RequestBody Person person) {
        return "person";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我想用curl向服务器发送请求时:

curl -i -X POST -HContent-Type:application/json  -HAccept:application/json http://localhost:8080/api/companies/addPerson -d "{ 'name': 'Gerry', 'age': 20, 'city': 'Sydney' }"
Run Code Online (Sandbox Code Playgroud)

我有一个HTTP/1.1 400错误请求:

HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1392
Server: Jetty(8.1.10.v20130312) 
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

spring json http spring-mvc

2
推荐指数
1
解决办法
8398
查看次数