com.raskasa.oksolr.SolrClientTest.java Source code

Java tutorial

Introduction

Here is the source code for com.raskasa.oksolr.SolrClientTest.java

Source

/*
 * Copyright (C) 2015 Ras Kasa Williams
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.raskasa.oksolr;

import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import java.io.File;
import org.junit.Test;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;

public final class SolrClientTest {

    @Test
    public void testExecute() throws Exception {

    }

    @Test
    public void testDefaultTimeout() throws Exception {
        SolrClient client = new SolrClient();
        assertThat(client.getConnectTimeout()).isEqualTo(10000); // 10 secs
        assertThat(client.getReadTimeout()).isEqualTo(10000); // 10 secs
        assertThat(client.getWriteTimeout()).isEqualTo(10000); // 10 secs
    }

    @Test
    public void testCustomTimeout() throws Exception {
        OkHttpClient okClient = new OkHttpClient();
        okClient.setConnectTimeout(20, SECONDS);
        okClient.setReadTimeout(20, SECONDS);
        okClient.setWriteTimeout(20, SECONDS);
        SolrClient solrClient = new SolrClient(okClient);

        assertThat(solrClient.getConnectTimeout()).isEqualTo(20000); // 20 secs
        assertThat(solrClient.getReadTimeout()).isEqualTo(20000); // 20 secs
        assertThat(solrClient.getWriteTimeout()).isEqualTo(20000); // 20 secs
    }

    @Test
    public void testInstallCache() throws Exception {
        SolrClient client = new SolrClient();
        client.installCache();
        Cache cache = client.getCache();

        assertThat(cache.getMaxSize()).isEqualTo(50 * 1024 * 1024); // 50 MiB
        assertThat(cache.getDirectory().toString())
                .isEqualTo(System.getProperty("user.home") + File.separator + "oksolr" + File.separator + "http");
    }
}