Skip to content

Commit

Permalink
added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexksikes committed Dec 15, 2014
1 parent 9f1abd8 commit be985c6
Showing 1 changed file with 65 additions and 0 deletions.
@@ -0,0 +1,65 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.search.stats;

import org.elasticsearch.index.search.stats.SearchStats;
import org.elasticsearch.index.search.stats.SearchStats.Stats;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class SearchStatsUnitTests extends ElasticsearchLuceneTestCase {

@Test
public void TestShardLevelSearchGroupStatsIssue7144() throws Exception {
// let's create two dummy search stats with groups
Map<String, Stats> groupStats1 = new HashMap<>();
Map<String, Stats> groupStats2 = new HashMap<>();
groupStats2.put("group1", new Stats(1, 1, 1, 1, 1, 1));
SearchStats searchStats1 = new SearchStats(new Stats(1, 1, 1, 1, 1, 1), 0, groupStats1);
SearchStats searchStats2 = new SearchStats(new Stats(1, 1, 1, 1, 1, 1), 0, groupStats2);

// adding these two search stats and checking group stats are correct
searchStats1.add(searchStats2);
checkStats(groupStats1.get("group1"), 1);

// another call, adding again ...
searchStats1.add(searchStats2);
checkStats(groupStats1.get("group1"), 2);

// making sure stats2 was not affected (this would previously return 2!)
checkStats(groupStats2.get("group1"), 1);

// adding again would then return wrong search stats (would return 4! instead of 3)
searchStats1.add(searchStats2);
checkStats(groupStats1.get("group1"), 3);
}

private void checkStats(Stats stats, long equalTo) {
assertEquals(equalTo, stats.getQueryCount());
assertEquals(equalTo, stats.getQueryTimeInMillis());
assertEquals(equalTo, stats.getQueryCurrent());
assertEquals(equalTo, stats.getFetchCount());
assertEquals(equalTo, stats.getFetchTimeInMillis());
assertEquals(equalTo, stats.getFetchCurrent());
}
}

0 comments on commit be985c6

Please sign in to comment.