小编Bom*_*mbe的帖子

打破java中的递归

递归是一种"分而治之"的风格,它在变小(树数据结构)时分裂,我希望它在发现违规时完全破坏,意味着打破所有递归路径,并返回true.这可能吗?

java recursion

24
推荐指数
4
解决办法
6万
查看次数

在SpringBootTest中测试COR

我试着写一个测试来验证我们的CORS设置.我这样配置CORS.

@Override
    public void configure(HttpSecurity httpSecurity) throws Exception {
//        super.configure(httpSecurity);
        httpSecurity.csrf().disable();
        httpSecurity.authorizeRequests().antMatchers("/**").permitAll();
        httpSecurity.cors();
    }

    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        List<String> allowedMethods = CORS_ALLOWED_METHODS;
        configuration.setAllowedMethods(allowedMethods);
        configuration.setAllowedOrigins(CORS_ALLOWED_ORIGINS);
        configuration.setAllowedHeaders(CORS_ALLOWED_HEADERS);
        configuration.setAllowCredentials(true);
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }
Run Code Online (Sandbox Code Playgroud)

我已经使用调试器验证了CORS_ALLOWED_METHODS我的测试运行时的值.

这是我的测试.当我在标题上断言时它失败了.

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("dev")
public class ControllerTests {

    @Autowired
    private WebApplicationContext wac;

    public MockMvc mockMvc;

    @Before
    public void setup() {
        DefaultMockMvcBuilder builder = MockMvcBuilders
                .webAppContextSetup(this.wac)
                .apply(SecurityMockMvcConfigurers.springSecurity())
                .dispatchOptions(true);
        this.mockMvc = builder.build();
    }

    @Test
    public void …
Run Code Online (Sandbox Code Playgroud)

testing spring-mvc cors spring-boot

12
推荐指数
1
解决办法
6606
查看次数

机器定期断块

当我使用apt-get安装或升级我的Ubuntu hardy系统时,我经常收到这样的消息:

$ sudo apt-get install foo
Reading package lists... Done
Segmentation faulty tree... 50%

$ sudo apt-get install foo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Segmentation fault

$ sudo apt-get install foo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct NULL not valid
Aborted

cc  -Os -g -Wall -DLOCAL_ROOT=\"/usr/share/polipo/www/\" -DDISK_CACHE_ROOT=\"/var/cache/polipo/\"  -DCHUNK_SIZE=16384   -c -o http_parse.o http_parse.c
http_parse.c:1564: internal compiler error: Segmentation fault …
Run Code Online (Sandbox Code Playgroud)

ubuntu apt segmentation-fault

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

在Kotlin和Guice中提供通用实例

我有一个Module提供List<String>使用@Provides注释方法的Guice .

class TestModule() : Module {
  override fun configure(binder: Binder) {}
  @Provides fun getStrings(): List<String> = listOf("foo", "bar")
}

class Test {
  @Test fun `provider can not deliver`() {
    val injector = Guice.createInjector(TestModule())
    injector.getInstance(object : Key<List<String>>() {})
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,测试失败了:

1) No implementation for java.util.List<? extends java.lang.String> was bound.
  while locating java.util.List<? extends java.lang.String>
Run Code Online (Sandbox Code Playgroud)

现在,这似乎与这个问题相同,但我不知道在哪里添加@JvmSuppressWildcards注释; 将它添加到getStrings()方法不会改变任何东西,因为它增加了objectgetInstance()呼叫.我如何让Guice做我想做的事?

guice kotlin

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

Kibana在120秒后关闭HTTP连接

所以,我和Kibana有这个问题,我不知道如何解决.我将从描述环境开始:

  • 12 Elasticsearch(版本2.1.2)节点.这些是安装了Linux/CentOS的各种AWS机器,使用r3/r4/i3实例类型,分布在三个AZ上.每台机器都有:
    • 800 GiB存储(EBS和SSD)
    • 30 GiB RAM
    • Kibana(4.3.3版)
    • elasticsearch.requestTimeout和elasticsearch.shardTimeout设置为1500000,即1500s,即25分钟.
  • 我们每天创建26个索引,保留12天,其中大多数有12个碎片和1个副本.
  • AWS ELB,用于将请求(非粘性)分发到所有12个节点.
    • ELB的空闲超时为900秒,即15分钟.

现在,当运行更复杂的查询时,Kibana在通过ELB访问时,会在两到三分钟后显示"网关超时"错误消息.Chrome中的网络控制台显示正在触发两个请求,第一个是确定请求的时间跨度的索引,第二个是结果数据的索引.第一个请求需要20到50秒才能成功,第二个请求总是在两分钟后完成504(网关超时).

当Kibana直接针对其中一个Elasticsearch节点运行查询时,查询大约需要7分钟并成功完成.

当没有ELB直接针对其中一个Kibana实例(使用curl)运行查询时,它在几乎两分钟后也会失败.使用Wireshark,我可以看到Kibana在120秒后关闭HTTP连接.

超时来自哪里?我怎么摆脱它?

kibana

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

在Java中使用静态方法作为Kotlin中的扩展方法

我有一个在Java中声明的静态方法:

class X {
    public static void foo(Y y) { … }
}
Run Code Online (Sandbox Code Playgroud)

我希望使用此方法作为YKotlin 中类型实例的扩展方法:

import X.foo
…
y.foo()
Run Code Online (Sandbox Code Playgroud)

那可能吗?我可以控制所有相关的源代码,例如添加注释.

java extension-methods kotlin

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

检查字符串是否包含字母表中的所有字母

检查给定字符串中所有字母的最佳逻辑是什么.

如果提供的字符串中有26个字母都可用,我想检查并执行操作.例如.用五十个酒壶包装我的盒子.

  1. 使用Hash会有用吗?
  2. 或者使用位图?或任何其他方式?

顺便说一句,我的代码将是Java.

java algorithm logic

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

Java for Kotlin编译器的注释类型参数

在Java中,我有以下方法:

public Optional<Foo> getFoo() {
    // always return some non-null value
}
Run Code Online (Sandbox Code Playgroud)

在Kotlin代码中,此方法的返回类型为Optional<Foo!>!。通过使用@Nonnull注释,我可以将其缩减为Optional<Foo!>(即,仅Foo不再对类型进行空检查)。

有没有办法注释使Kotlin编译器对返回值正确进行null检查的方法?

annotations non-nullable kotlin

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