Skip to content

Commit

Permalink
Added QueryTimeLookup functionality integration style tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garyluoex committed Sep 2, 2016
1 parent 46b4eee commit f468ce2
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 112 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Current

### Added:

- [Lookup Dimension Serializer]()
- [QueryTimeLookup Functionality Testing](https://github.com/yahoo/fili/pull/34)
* Added two tests `LookupDimensionFilteringDataServeletSpec` and `LookupDimensionGroupingDataServletSpec` to test QTL functionality
* Modified some testing resources (PETS table and corresponding dimensions) to allow better testing on `LookupDimension`s

- [Lookup Dimension Serializer](https://github.com/yahoo/fili/pull/31)
* Created `LookupDimensionToDimensionSpec` serializer for `LookupDimension`
* Created corresponding tests for `LookupDimensionToDimensionSpec` in `LookupDimensionToDimensionSpecSpec`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.yahoo.bard.webservice.data.config.ResourceDictionaries;
import com.yahoo.bard.webservice.data.config.dimension.DimensionConfig;
import com.yahoo.bard.webservice.data.config.dimension.DimensionLoader;
import com.yahoo.bard.webservice.data.config.dimension.KeyValueStoreDimensionLoader;
import com.yahoo.bard.webservice.data.config.dimension.TypeAwareDimensionLoader;
import com.yahoo.bard.webservice.data.config.metric.MetricLoader;
import com.yahoo.bard.webservice.data.config.table.TableLoader;
import com.yahoo.bard.webservice.data.dimension.DimensionDictionary;
Expand Down Expand Up @@ -837,7 +837,7 @@ protected ConfigurationLoader buildConfigurationLoader(
* @return a Dimension Loader instance
*/
protected DimensionLoader getDimensionLoader() {
return new KeyValueStoreDimensionLoader(getDimensionConfigurations());
return new TypeAwareDimensionLoader(getDimensionConfigurations());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.yahoo.bard.webservice.data.cache.StubDataCache
import com.yahoo.bard.webservice.data.cache.TupleDataCache
import com.yahoo.bard.webservice.data.config.ConfigurationLoader
import com.yahoo.bard.webservice.data.config.dimension.DimensionConfig
import com.yahoo.bard.webservice.data.config.dimension.KeyValueStoreDimensionLoader
import com.yahoo.bard.webservice.data.config.dimension.TypeAwareDimensionLoader
import com.yahoo.bard.webservice.data.config.dimension.TestDimensions
import com.yahoo.bard.webservice.data.config.metric.MetricLoader
import com.yahoo.bard.webservice.data.config.table.TableLoader
Expand Down Expand Up @@ -171,7 +171,7 @@ public class AbstractBinderFactorySpec extends Specification {
cl.dictionaries != null
cl.tableLoader != null
cl.metricLoader != null
cl.dimensionLoader instanceof KeyValueStoreDimensionLoader
cl.dimensionLoader instanceof TypeAwareDimensionLoader
}

def "test configure bindings"() {
Expand Down Expand Up @@ -436,7 +436,7 @@ public class AbstractBinderFactorySpec extends Specification {
ConfigurationLoader cl = localBinderFactory.buildConfigurationLoader()

then:
cl.dimensionLoader instanceof KeyValueStoreDimensionLoader
cl.dimensionLoader instanceof TypeAwareDimensionLoader
cl.metricLoader == metricLoader
cl.tableLoader == tableLoader
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@ import spock.lang.Specification
*/
class TypeAwareDimensionLoaderSpec extends Specification {

LinkedHashSet<DimensionConfig> lookupDimensionConfigurations
LinkedHashSet<DimensionConfig> dimensionConfigurations
DimensionDictionary dimensionDictionary

def setup() {
lookupDimensionConfigurations = new TestLookupDimensions().getAllDimensionConfigurations()
dimensionConfigurations = new TestDimensions().getAllDimensionConfigurations()
dimensionDictionary = new DimensionDictionary()
}

def "Test dimension loader for Lookup dimension"() {
given: "A Type Aware Dimension Loader with a list of dimension configurations"
TypeAwareDimensionLoader typeAwareDimensionLoader = new TypeAwareDimensionLoader(lookupDimensionConfigurations)
TypeAwareDimensionLoader typeAwareDimensionLoader = new TypeAwareDimensionLoader(dimensionConfigurations)

when:
typeAwareDimensionLoader.loadDimensionDictionary(dimensionDictionary)

then:
dimensionDictionary.findByApiName("size").getClass() == LookupDimension.class
dimensionDictionary.findByApiName("breed").getClass() == LookupDimension.class
}

def "Test dimension loader for KeyValueStore dimension"() {
Expand All @@ -41,16 +39,16 @@ class TypeAwareDimensionLoaderSpec extends Specification {
typeAwareDimensionLoader.loadDimensionDictionary(dimensionDictionary)

then:
dimensionDictionary.findByApiName("breed").getClass() == KeyValueStoreDimension.class
dimensionDictionary.findByApiName("color").getClass() == KeyValueStoreDimension.class
}

def "Test dimension loader for a dimension type that is not defined"() {
given: "A Type Aware Dimension loader with a list of dimension configurations"
DimensionConfig dimensionConfiguration = Mock(DimensionConfig)
dimensionConfiguration.getApiName() >> "foo"
dimensionConfiguration.getType() >> String.class
lookupDimensionConfigurations.add(dimensionConfiguration)
TypeAwareDimensionLoader typeAwareDimensionLoader = new TypeAwareDimensionLoader(lookupDimensionConfigurations)
dimensionConfigurations.add(dimensionConfiguration)
TypeAwareDimensionLoader typeAwareDimensionLoader = new TypeAwareDimensionLoader(dimensionConfigurations)

when:
typeAwareDimensionLoader.loadDimensionDictionary(dimensionDictionary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class TableFullViewProcessorSpec extends Specification {
def "Check table meta data info at grain level"() {

setup:
String expectedResponse = "[name:all, description:The pets all grain, metrics:[[category:General, name:rowNum, longName:rowNum, uri:http://localhost:9998/v1/rowNum], [category:General, name:limbs, longName:limbs, uri:http://localhost:9998/v1/limbs], [category:General, name:dayAvgLimbs, longName:dayAvgLimbs, uri:http://localhost:9998/v1/dayAvgLimbs]], retention:P1Y, longName:All, dimensions:[[category:General, name:species, longName:species, uri:http://localhost:9998/v1/species, cardinality:0], [category:General, name:sex, longName:sex, uri:http://localhost:9998/v1/sex, cardinality:0], [category:General, name:breed, longName:breed, uri:http://localhost:9998/v1/breed, cardinality:0]]]"
String expectedResponse = "[description:The pets all grain, dimensions:[[category:General, name:sex, longName:sex, uri:http://localhost:9998/v1/sex, cardinality:0], [category:General, name:species, longName:species, uri:http://localhost:9998/v1/species, cardinality:0], [category:General, name:breed, longName:breed, uri:http://localhost:9998/v1/breed, cardinality:0]], longName:All, metrics:[[category:General, name:rowNum, longName:rowNum, uri:http://localhost:9998/v1/rowNum], [category:General, name:limbs, longName:limbs, uri:http://localhost:9998/v1/limbs], [category:General, name:dayAvgLimbs, longName:dayAvgLimbs, uri:http://localhost:9998/v1/dayAvgLimbs]], name:all, retention:P1Y]"
LogicalTable petsTable = petsShapesTables.find {it.getName() == "pets"}

when:
TableGrainView tableGrainView = fullViewProcessor.formatTableGrain(petsTable, "all", uriInfo)

then:
tableGrainView.toString() == expectedResponse
tableGrainView.sort().toString() == expectedResponse
}

def "check all the tables full view at grain level"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// Licensed under the terms of the Apache license. Please see LICENSE file distributed with this work for terms.
package com.yahoo.bard.webservice.web.endpoints

import static com.yahoo.bard.webservice.util.JsonSortStrategy.SORT_BOTH

import com.yahoo.bard.webservice.application.JerseyTestBinder
import com.yahoo.bard.webservice.data.time.GranularityParser
import com.yahoo.bard.webservice.data.time.StandardGranularityParser
import com.yahoo.bard.webservice.models.druid.client.impl.TestDruidWebService
import com.yahoo.bard.webservice.table.availability.AvailabilityTestingUtils
import com.yahoo.bard.webservice.util.GroovyTestUtils
import com.yahoo.bard.webservice.util.JsonSortStrategy

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
Expand Down Expand Up @@ -106,7 +105,7 @@ abstract class BaseDataServletComponentSpec extends Specification {
}

// Most aspects of a Druid query are order-independent, so normalize both lists and maps.
GroovyTestUtils.compareJson(jsonQuery, getExpectedDruidQuery(), SORT_BOTH)
compareResult(jsonQuery, getExpectedDruidQuery(), JsonSortStrategy.SORT_BOTH)
}

@Timeout(10)
Expand Down Expand Up @@ -135,8 +134,8 @@ abstract class BaseDataServletComponentSpec extends Specification {
validateJson(expectedApiResponse)
}

boolean compareResult(String result, String expectedResult) {
GroovyTestUtils.compareJson(result, expectedResult)
boolean compareResult(String result, String expectedResult, JsonSortStrategy sortStrategy = JsonSortStrategy.SORT_MAPS) {
GroovyTestUtils.compareJson(result, expectedResult, sortStrategy)
}

/**
Expand Down
Loading

0 comments on commit f468ce2

Please sign in to comment.