<commit_before>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;

import com.yahoo.prelude.query.QueryException;
import com.yahoo.search.Query;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * @author baldersheim
 */
public class SoftTimeoutTestCase {
    @Test
    public void testDefaultsInQuery() {
        Query query=new Query("?query=test");
        assertNull(query.getRanking().getSoftTimeout().getEnable());
        assertNull(query.getRanking().getSoftTimeout().getFactor());
        assertNull(query.getRanking().getSoftTimeout().getTailcost());
    }

    @Test
    public void testQueryOverride() {
        Query query=new Query("?query=test&ranking.softtimeout.enable&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3");
        assertTrue(query.getRanking().getSoftTimeout().getEnable());
        assertEquals(Double.valueOf(0.7), query.getRanking().getSoftTimeout().getFactor());
        assertEquals(Double.valueOf(0.3), query.getRanking().getSoftTimeout().getTailcost());
        query.prepare();
        assertEquals("true", query.getRanking().getProperties().get("vespa.softtimeout.enable").get(0));
        assertEquals("0.7", query.getRanking().getProperties().get("vespa.softtimeout.factor").get(0));
        assertEquals("0.3", query.getRanking().getProperties().get("vespa.softtimeout.tailcost").get(0));
    }

    private void verifyException(String key, String value) {
        try {
            new Query("?query=test&ranking.softtimeout."+key+"="+value);
            assertFalse(true);
        } catch (QueryException e) {
            assertEquals("Invalid request parameter", e.getMessage());
            assertEquals("Could not set 'ranking.softtimeout." + key + "' to '" + value +"'", e.getCause().getMessage());
            assertEquals(key + " must be in the range [0.0, 1.0]. It is " + value, e.getCause().getCause().getMessage());
        }
    }
    @Test
    public void testLimits() {
        verifyException("factor", "-0.1");
        verifyException("factor", "1.1");
        verifyException("tailcost", "-0.1");
        verifyException("tailcost", "1.1");
    }
}
<commit_msg>Expect the right error message<commit_after>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;

import com.yahoo.prelude.query.QueryException;
import com.yahoo.search.Query;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * @author baldersheim
 */
public class SoftTimeoutTestCase {
    @Test
    public void testDefaultsInQuery() {
        Query query=new Query("?query=test");
        assertNull(query.getRanking().getSoftTimeout().getEnable());
        assertNull(query.getRanking().getSoftTimeout().getFactor());
        assertNull(query.getRanking().getSoftTimeout().getTailcost());
    }

    @Test
    public void testQueryOverride() {
        Query query=new Query("?query=test&ranking.softtimeout.enable&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3");
        assertTrue(query.getRanking().getSoftTimeout().getEnable());
        assertEquals(Double.valueOf(0.7), query.getRanking().getSoftTimeout().getFactor());
        assertEquals(Double.valueOf(0.3), query.getRanking().getSoftTimeout().getTailcost());
        query.prepare();
        assertEquals("true", query.getRanking().getProperties().get("vespa.softtimeout.enable").get(0));
        assertEquals("0.7", query.getRanking().getProperties().get("vespa.softtimeout.factor").get(0));
        assertEquals("0.3", query.getRanking().getProperties().get("vespa.softtimeout.tailcost").get(0));
    }

    private void verifyException(String key, String value) {
        try {
            new Query("?query=test&ranking.softtimeout."+key+"="+value);
            assertFalse(true);
        } catch (QueryException e) {
            assertEquals("Invalid request parameter", e.getMessage());
            assertEquals("Could not set 'ranking.softtimeout." + key + "' to '" + value +"'", e.getCause().getMessage());
            assertEquals(key + " must be in the range [0.0, 1.0], got " + value, e.getCause().getCause().getMessage());
        }
    }
    @Test
    public void testLimits() {
        verifyException("factor", "-0.1");
        verifyException("factor", "1.1");
        verifyException("tailcost", "-0.1");
        verifyException("tailcost", "1.1");
    }
}

{'fraction_non_alphanumeric': 0.16079734219269104, 'fraction_numerical': 0.014617940199335547, 'mean_word_length': 3.5386934673366834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '536461', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1269, 'n_words': 231}