Пример #1
0
 public void addNeighbouring(Feature[] neighbouring) {
   if (this.neighbouring == null) {
     this.neighbouring = neighbouring;
   } else {
     this.neighbouring = ObjectArrays.concat(this.neighbouring, neighbouring, Feature.class);
   }
 }
Пример #2
0
  /**
   * Returns all config options for the given component.
   *
   * @param component
   * @return
   */
  public static Map<ConfigOption, Class<?>> getConfigOptionTypes(
      Class<?> component, boolean useSuperTypes) {
    Map<ConfigOption, Class<?>> optionTypes =
        new TreeMap<ConfigOption, Class<?>>(
            new Comparator<ConfigOption>() {

              @Override
              public int compare(ConfigOption o1, ConfigOption o2) {
                return o1.name().compareTo(o2.name());
              }
            });
    Field[] fields = component.getDeclaredFields();
    if (useSuperTypes) {
      if (useSuperTypes) {
        fields =
            ObjectArrays.concat(fields, component.getSuperclass().getDeclaredFields(), Field.class);
      }
    }
    for (Field f : fields) {
      ConfigOption option = f.getAnnotation(ConfigOption.class);
      if (option != null) {
        optionTypes.put(option, f.getType());
      }
    }
    return optionTypes;
  }
Пример #3
0
 public IAndroidTarget[] getTargets(boolean includeMissing) {
   IAndroidTarget[] result = getTargets();
   if (includeMissing) {
     result = ObjectArrays.concat(result, getMissingTargets(), IAndroidTarget.class);
   }
   return result;
 }
Пример #4
0
 /** Adds a SQL condition to the WHERE clause (joined using AND). */
 public QueryBuilder where(String sqlCondition, String... args) {
   if (sqlCondition != null && !sqlCondition.isEmpty()) {
     mCondition += " and (" + sqlCondition + ")";
     mArgs = args == null ? mArgs : ObjectArrays.concat(mArgs, args, String.class);
   }
   return this;
 }
Пример #5
0
 @Test
 public void testCollectionInstance() {
   Maps.newLinkedHashMap();
   Lists.newArrayList();
   Sets.newHashSet();
   ObjectArrays.newArray(Integer.class, 10);
 }
  private AdPrincipal getAdPrincipal(DirContext boundContext, AdCredentials credentials)
      throws AuthenticationException {
    try {
      SearchControls searchCtls = new SearchControls();
      searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
      String[] attributeNames =
          ObjectArrays.concat(
              configuration.getAttributeNames(),
              configuration.getBinaryAttributeNames(),
              String.class);
      searchCtls.setReturningAttributes(attributeNames);
      NamingEnumeration<SearchResult> results =
          boundContext.search(
              configuration.getDomainBase(),
              String.format(
                  configuration.getUsernameFilterTemplate(), credentials.getsAMAccountName()),
              searchCtls);
      SearchResult userResult = results.hasMoreElements() ? results.next() : null;

      if (userResult == null || results.hasMoreElements()) {
        throw new AuthenticationException(
            String.format(
                "Inconsistent search for %s. Bind succeeded but post bind lookup failed. Assumptions/logic failed?",
                credentials.getUsername()));
      }

      Map<String, Object> attributes = AdUtilities.simplify(userResult.getAttributes());
      return new AdPrincipal(
          (String) attributes.get(SCHEMA_ATTR_SAMACCOUNTNAME),
          AdUtilities.extractDNParticles((Set) attributes.get(SCHEMA_ATTR_MEMBEROF), "cn"),
          attributes);
    } catch (NamingException e) {
      throw new AuthenticationException("User search failed. Configuration error?", e);
    }
  }
Пример #7
0
  /**
   * Append POP3 Specific config options
   *
   * @return
   */
  @Configuration()
  public Option[] config() {
    return ObjectArrays.concat(
        super.config(),
        options(
            // POP3 Test Bundles
            mavenBundle().groupId("commons-net").artifactId("commons-net").versionAsInProject(),
            mavenBundle()
                .groupId("org.apache.james.protocols")
                .artifactId("protocols-netty")
                .versionAsInProject(),
            mavenBundle()
                .groupId("org.apache.james.protocols")
                .artifactId("protocols-api")
                .versionAsInProject(),
            mavenBundle()
                .groupId("org.apache.james.protocols")
                .artifactId("protocols-pop3")
                .versionAsInProject(),
            mavenBundle().groupId("io.netty").artifactId("netty").versionAsInProject(),

            // ElasticInbox Bundles
            scanDir("../modules/pop3/target/")),
        Option.class);
  }
Пример #8
0
 private static void logError(Throwable t, String format, Object... args) {
   if (isExpectedError(t)) {
     log.error(format + ": %s", ObjectArrays.concat(args, t));
   } else {
     log.error(t, format, args);
   }
 }
Пример #9
0
 @Override
 protected Module[] getTestCustomModules() {
   Module[] modules = super.getTestCustomModules();
   if (modules == null) {
     modules = new Module[0];
   }
   modules = ObjectArrays.concat(modules, new SecurityModule());
   return modules;
 }
Пример #10
0
 /**
  * Launch VOLD.
  *
  * @param javaArgs VOLD arguments, may be <code>null</code>
  * @throws IOException
  */
 private void launchVold(final String[] javaArgs) throws IOException {
   final String classpath = System.getProperty("java.class.path");
   final String main = Vold.class.getName();
   String[] args = new String[] {"java", "-cp", classpath, main};
   if (javaArgs != null) {
     args = ObjectArrays.concat(args, javaArgs, String.class);
   }
   RunCmdUtils.runCmd(args, this, true);
 }
Пример #11
0
  @Test
  public void variablesAreImportedProperly_whenResourcesAreImportingThemselvesInLoop()
      throws Exception {

    // those files imports forms a cycle
    final IFile sourceFile =
        projectProvider.createFile(
            "res1.robot",
            ObjectArrays.concat(
                createVariablesSection("1"),
                createResourceImportSettingsSection("res2.robot"),
                String.class));
    projectProvider.createFile(
        "res2.robot",
        ObjectArrays.concat(
            createVariablesSection("2"),
            createResourceImportSettingsSection("res3.robot"),
            String.class));
    projectProvider.createFile(
        "res3.robot",
        ObjectArrays.concat(
            createVariablesSection("3"),
            createResourceImportSettingsSection("res1.robot"),
            String.class));

    final Set<String> visitedVars = new HashSet<>();
    final VariableDefinitionLocator locator =
        new VariableDefinitionLocator(sourceFile, new RobotModel());
    locator.locateVariableDefinition(variableDetector(visitedVars));
    assertThat(visitedVars)
        .containsOnly(
            "scalar_1",
            "list_1",
            "dict_1",
            "invalid_1",
            "scalar_2",
            "list_2",
            "dict_2",
            "invalid_2",
            "scalar_3",
            "list_3",
            "dict_3",
            "invalid_3");
  }
Пример #12
0
  protected static HttpResponse doGet(String resource, Header[] headers) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(AppFabricTestBase.getEndPoint(resource));

    if (headers != null) {
      get.setHeaders(ObjectArrays.concat(AUTH_HEADER, headers));
    } else {
      get.setHeader(AUTH_HEADER);
    }
    return client.execute(get);
  }
Пример #13
0
  protected static HttpResponse doPost(String resource, String body, Header[] headers)
      throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(AppFabricTestBase.getEndPoint(resource));

    if (body != null) {
      post.setEntity(new StringEntity(body));
    }

    if (headers != null) {
      post.setHeaders(ObjectArrays.concat(AUTH_HEADER, headers));
    } else {
      post.setHeader(AUTH_HEADER);
    }
    return client.execute(post);
  }
Пример #14
0
  @Test
  public void show() {
    List<User> personList = Lists.newLinkedList();
    Set<User> personSet = Sets.newHashSet();
    Map<String, User> personMap = Maps.newHashMap();
    Integer[] intArrays = ObjectArrays.newArray(Integer.class, 10);

    // --------------------

    Set<String> set = Sets.newHashSet("one", "two", "three");
    List<String> list = Lists.newArrayList("one", "two", "three");
    Map<String, String> map = ImmutableMap.of("ON", "TRUE", "OFF", "FALSE");

    // 2,简化集合的初始化
    List<User> personList2 = Lists.newArrayList(new User("zhuc-1", 20), new User("zhuc-2", 25));
    Set<User> personSet2 = Sets.newHashSet(new User("zhuc-1", 20), new User("zhuc-2", 25));
    Map<String, User> personMap2 =
        ImmutableMap.of("hello", new User("zhuc-1", 20), "f**k", new User("zhuc-2", 25));
  }
Пример #15
0
 protected <T> T[] standardToArray(T[] var1) {
   return ObjectArrays.toArrayImpl(this, var1);
 }
Пример #16
0
 public static <C extends Comparable<? super C>> Continuum<C> over(C first, C... rest) {
   return over(Arrays.asList(ObjectArrays.concat(first, rest)));
 }
Пример #17
0
 /**
  * Add to the list of enchantments applicable by the anvil from a book
  *
  * @param enchantment
  */
 public static void addToBookList(Enchantment enchantment) {
   ObjectArrays.concat(field_92090_c, enchantment);
 }
Пример #18
0
@RunWith(Parameterized.class)
public class SelectQueryRunnerTest {
  // copied from druid.sample.tsv
  public static final String[] V_0112 = {
    "2011-01-12T00:00:00.000Z	spot	automotive	preferred	apreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	business	preferred	bpreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	entertainment	preferred	epreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	health	preferred	hpreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	mezzanine	preferred	mpreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	news	preferred	npreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	premium	preferred	ppreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	technology	preferred	tpreferred	100.000000",
    "2011-01-12T00:00:00.000Z	spot	travel	preferred	tpreferred	100.000000",
    "2011-01-12T00:00:00.000Z	total_market	mezzanine	preferred	mpreferred	1000.000000",
    "2011-01-12T00:00:00.000Z	total_market	premium	preferred	ppreferred	1000.000000",
    "2011-01-12T00:00:00.000Z	upfront	mezzanine	preferred	mpreferred	800.000000	value",
    "2011-01-12T00:00:00.000Z	upfront	premium	preferred	ppreferred	800.000000	value"
  };
  public static final String[] V_0113 = {
    "2011-01-13T00:00:00.000Z	spot	automotive	preferred	apreferred	94.874713",
    "2011-01-13T00:00:00.000Z	spot	business	preferred	bpreferred	103.629399",
    "2011-01-13T00:00:00.000Z	spot	entertainment	preferred	epreferred	110.087299",
    "2011-01-13T00:00:00.000Z	spot	health	preferred	hpreferred	114.947403",
    "2011-01-13T00:00:00.000Z	spot	mezzanine	preferred	mpreferred	104.465767",
    "2011-01-13T00:00:00.000Z	spot	news	preferred	npreferred	102.851683",
    "2011-01-13T00:00:00.000Z	spot	premium	preferred	ppreferred	108.863011",
    "2011-01-13T00:00:00.000Z	spot	technology	preferred	tpreferred	111.356672",
    "2011-01-13T00:00:00.000Z	spot	travel	preferred	tpreferred	106.236928",
    "2011-01-13T00:00:00.000Z	total_market	mezzanine	preferred	mpreferred	1040.945505",
    "2011-01-13T00:00:00.000Z	total_market	premium	preferred	ppreferred	1689.012875",
    "2011-01-13T00:00:00.000Z	upfront	mezzanine	preferred	mpreferred	826.060182	value",
    "2011-01-13T00:00:00.000Z	upfront	premium	preferred	ppreferred	1564.617729	value"
  };

  public static final QuerySegmentSpec I_0112_0114 =
      new LegacySegmentSpec(new Interval("2011-01-12/2011-01-14"));
  public static final String[] V_0112_0114 = ObjectArrays.concat(V_0112, V_0113, String.class);

  @Parameterized.Parameters(name = "{0}:descending={1}")
  public static Iterable<Object[]> constructorFeeder() throws IOException {
    return QueryRunnerTestHelper.cartesian(
        QueryRunnerTestHelper.makeQueryRunners(
            new SelectQueryRunnerFactory(
                new SelectQueryQueryToolChest(
                    new DefaultObjectMapper(),
                    QueryRunnerTestHelper.NoopIntervalChunkingQueryRunnerDecorator()),
                new SelectQueryEngine(),
                QueryRunnerTestHelper.NOOP_QUERYWATCHER)),
        Arrays.asList(false, true));
  }

  private final QueryRunner runner;
  private final boolean descending;

  public SelectQueryRunnerTest(QueryRunner runner, boolean descending) {
    this.runner = runner;
    this.descending = descending;
  }

  private Druids.SelectQueryBuilder newTestQuery() {
    return Druids.newSelectQueryBuilder()
        .dataSource(new TableDataSource(QueryRunnerTestHelper.dataSource))
        .dimensionSpecs(DefaultDimensionSpec.toSpec(Arrays.<String>asList()))
        .metrics(Arrays.<String>asList())
        .intervals(QueryRunnerTestHelper.fullOnInterval)
        .granularity(QueryRunnerTestHelper.allGran)
        .pagingSpec(PagingSpec.newSpec(3))
        .descending(descending);
  }

  @Test
  public void testFullOnSelect() {
    SelectQuery query = newTestQuery().intervals(I_0112_0114).build();

    HashMap<String, Object> context = new HashMap<String, Object>();
    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());

    PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
    List<Result<SelectResultValue>> expectedResults =
        toExpected(
            toEvents(new String[] {EventHolder.timestampKey + ":TIME"}, V_0112_0114),
            offset.startOffset(),
            offset.threshold());
    verify(expectedResults, results);
  }

  @Test
  public void testSequentialPaging() {
    int[] asc = {2, 5, 8, 11, 14, 17, 20, 23, 25};
    int[] dsc = {-3, -6, -9, -12, -15, -18, -21, -24, -26};
    int[] expected = descending ? dsc : asc;

    SelectQuery query = newTestQuery().intervals(I_0112_0114).build();
    for (int offset : expected) {
      List<Result<SelectResultValue>> results =
          Sequences.toList(
              runner.run(query, ImmutableMap.of()),
              Lists.<Result<SelectResultValue>>newArrayList());

      Assert.assertEquals(1, results.size());

      SelectResultValue result = results.get(0).getValue();
      Map<String, Integer> pagingIdentifiers = result.getPagingIdentifiers();
      Assert.assertEquals(
          offset, pagingIdentifiers.get(QueryRunnerTestHelper.segmentId).intValue());

      Map<String, Integer> next = PagingSpec.next(pagingIdentifiers, descending);
      query = query.withPagingSpec(new PagingSpec(next, 3));
    }

    query = newTestQuery().intervals(I_0112_0114).build();
    for (int offset : expected) {
      List<Result<SelectResultValue>> results =
          Sequences.toList(
              runner.run(query, ImmutableMap.of()),
              Lists.<Result<SelectResultValue>>newArrayList());

      Assert.assertEquals(1, results.size());

      SelectResultValue result = results.get(0).getValue();
      Map<String, Integer> pagingIdentifiers = result.getPagingIdentifiers();
      Assert.assertEquals(
          offset, pagingIdentifiers.get(QueryRunnerTestHelper.segmentId).intValue());

      // use identifier as-is but with fromNext=true
      query = query.withPagingSpec(new PagingSpec(pagingIdentifiers, 3, true));
    }
  }

  @Test
  public void testFullOnSelectWithDimensionSpec() {
    Map<String, String> map = new HashMap<>();
    map.put("automotive", "automotive0");
    map.put("business", "business0");
    map.put("entertainment", "entertainment0");
    map.put("health", "health0");
    map.put("mezzanine", "mezzanine0");
    map.put("news", "news0");
    map.put("premium", "premium0");
    map.put("technology", "technology0");
    map.put("travel", "travel0");

    SelectQuery query =
        newTestQuery()
            .dimensionSpecs(
                Arrays.<DimensionSpec>asList(
                    new DefaultDimensionSpec(QueryRunnerTestHelper.marketDimension, "mar"),
                    new ExtractionDimensionSpec(
                        QueryRunnerTestHelper.qualityDimension,
                        "qual",
                        new LookupExtractionFn(
                            new MapLookupExtractor(map, true), false, null, true, false)),
                    new DefaultDimensionSpec(QueryRunnerTestHelper.placementDimension, "place")))
            .build();

    HashMap<String, Object> context = new HashMap<String, Object>();
    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());

    List<Result<SelectResultValue>> expectedResultsAsc =
        Arrays.asList(
            new Result<SelectResultValue>(
                new DateTime("2011-01-12T00:00:00.000Z"),
                new SelectResultValue(
                    ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2),
                    Arrays.asList(
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            0,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-01-12T00:00:00.000Z"))
                                .put("mar", "spot")
                                .put("qual", "automotive0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 100.000000F)
                                .build()),
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            1,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-01-12T00:00:00.000Z"))
                                .put("mar", "spot")
                                .put("qual", "business0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 100.000000F)
                                .build()),
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            2,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-01-12T00:00:00.000Z"))
                                .put("mar", "spot")
                                .put("qual", "entertainment0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 100.000000F)
                                .build())))));

    List<Result<SelectResultValue>> expectedResultsDsc =
        Arrays.asList(
            new Result<SelectResultValue>(
                new DateTime("2011-01-12T00:00:00.000Z"),
                new SelectResultValue(
                    ImmutableMap.of(QueryRunnerTestHelper.segmentId, -3),
                    Arrays.asList(
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            -1,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-04-15T00:00:00.000Z"))
                                .put("mar", "upfront")
                                .put("qual", "premium0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 780.27197265625F)
                                .build()),
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            -2,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-04-15T00:00:00.000Z"))
                                .put("mar", "upfront")
                                .put("qual", "mezzanine0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 962.731201171875F)
                                .build()),
                        new EventHolder(
                            QueryRunnerTestHelper.segmentId,
                            -3,
                            new ImmutableMap.Builder<String, Object>()
                                .put(
                                    EventHolder.timestampKey,
                                    new DateTime("2011-04-15T00:00:00.000Z"))
                                .put("mar", "total_market")
                                .put("qual", "premium0")
                                .put("place", "preferred")
                                .put(QueryRunnerTestHelper.indexMetric, 1029.0570068359375F)
                                .build())))));

    verify(descending ? expectedResultsDsc : expectedResultsAsc, results);
  }

  @Test
  public void testSelectWithDimsAndMets() {
    SelectQuery query =
        newTestQuery()
            .intervals(I_0112_0114)
            .dimensionSpecs(DefaultDimensionSpec.toSpec(QueryRunnerTestHelper.marketDimension))
            .metrics(Arrays.asList(QueryRunnerTestHelper.indexMetric))
            .build();

    HashMap<String, Object> context = new HashMap<String, Object>();
    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());

    PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
    List<Result<SelectResultValue>> expectedResults =
        toExpected(
            toEvents(
                new String[] {
                  EventHolder.timestampKey + ":TIME",
                  QueryRunnerTestHelper.marketDimension + ":STRING",
                  null,
                  null,
                  null,
                  QueryRunnerTestHelper.indexMetric + ":FLOAT"
                },
                V_0112_0114),
            offset.startOffset(),
            offset.threshold());
    verify(expectedResults, results);
  }

  @Test
  public void testSelectPagination() {
    SelectQuery query =
        newTestQuery()
            .intervals(I_0112_0114)
            .dimensionSpecs(DefaultDimensionSpec.toSpec(QueryRunnerTestHelper.qualityDimension))
            .metrics(Arrays.asList(QueryRunnerTestHelper.indexMetric))
            .pagingSpec(new PagingSpec(toPagingIdentifier(3, descending), 3))
            .build();

    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, Maps.newHashMap()), Lists.<Result<SelectResultValue>>newArrayList());

    PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
    List<Result<SelectResultValue>> expectedResults =
        toExpected(
            toEvents(
                new String[] {EventHolder.timestampKey + ":TIME", "foo:NULL", "foo2:NULL"},
                V_0112_0114),
            offset.startOffset(),
            offset.threshold());
    verify(expectedResults, results);
  }

  @Test
  public void testFullOnSelectWithFilter() {
    // startDelta + threshold pairs
    for (int[] param : new int[][] {{3, 3}, {0, 1}, {5, 5}, {2, 7}, {3, 0}}) {
      SelectQuery query =
          newTestQuery()
              .intervals(I_0112_0114)
              .filters(new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "spot", null))
              .granularity(QueryRunnerTestHelper.dayGran)
              .dimensionSpecs(DefaultDimensionSpec.toSpec(QueryRunnerTestHelper.qualityDimension))
              .metrics(Lists.<String>newArrayList(QueryRunnerTestHelper.indexMetric))
              .pagingSpec(new PagingSpec(toPagingIdentifier(param[0], descending), param[1]))
              .build();

      HashMap<String, Object> context = new HashMap<String, Object>();
      Iterable<Result<SelectResultValue>> results =
          Sequences.toList(
              runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());

      final List<List<Map<String, Object>>> events =
          toEvents(
              new String[] {
                EventHolder.timestampKey + ":TIME",
                null,
                QueryRunnerTestHelper.qualityDimension + ":STRING",
                null,
                null,
                QueryRunnerTestHelper.indexMetric + ":FLOAT"
              },
              // filtered values with day granularity
              new String[] {
                "2011-01-12T00:00:00.000Z	spot	automotive	preferred	apreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	business	preferred	bpreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	entertainment	preferred	epreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	health	preferred	hpreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	mezzanine	preferred	mpreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	news	preferred	npreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	premium	preferred	ppreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	technology	preferred	tpreferred	100.000000",
                "2011-01-12T00:00:00.000Z	spot	travel	preferred	tpreferred	100.000000"
              },
              new String[] {
                "2011-01-13T00:00:00.000Z	spot	automotive	preferred	apreferred	94.874713",
                "2011-01-13T00:00:00.000Z	spot	business	preferred	bpreferred	103.629399",
                "2011-01-13T00:00:00.000Z	spot	entertainment	preferred	epreferred	110.087299",
                "2011-01-13T00:00:00.000Z	spot	health	preferred	hpreferred	114.947403",
                "2011-01-13T00:00:00.000Z	spot	mezzanine	preferred	mpreferred	104.465767",
                "2011-01-13T00:00:00.000Z	spot	news	preferred	npreferred	102.851683",
                "2011-01-13T00:00:00.000Z	spot	premium	preferred	ppreferred	108.863011",
                "2011-01-13T00:00:00.000Z	spot	technology	preferred	tpreferred	111.356672",
                "2011-01-13T00:00:00.000Z	spot	travel	preferred	tpreferred	106.236928"
              });

      PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
      List<Result<SelectResultValue>> expectedResults =
          toExpected(events, offset.startOffset(), offset.threshold());
      verify(expectedResults, results);
    }
  }

  @Test
  public void testFullSelectNoResults() {
    SelectQuery query =
        newTestQuery()
            .intervals(I_0112_0114)
            .filters(
                new AndDimFilter(
                    Arrays.<DimFilter>asList(
                        new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "spot", null),
                        new SelectorDimFilter(QueryRunnerTestHelper.marketDimension, "foo", null))))
            .build();

    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, Maps.newHashMap()), Lists.<Result<SelectResultValue>>newArrayList());

    List<Result<SelectResultValue>> expectedResults =
        Arrays.asList(
            new Result<SelectResultValue>(
                new DateTime("2011-01-12T00:00:00.000Z"),
                new SelectResultValue(
                    ImmutableMap.<String, Integer>of(), Lists.<EventHolder>newArrayList())));

    verify(expectedResults, results);
  }

  @Test
  public void testFullSelectNoDimensionAndMetric() {
    SelectQuery query =
        newTestQuery()
            .intervals(I_0112_0114)
            .dimensionSpecs(DefaultDimensionSpec.toSpec("foo"))
            .metrics(Lists.<String>newArrayList("foo2"))
            .build();

    Iterable<Result<SelectResultValue>> results =
        Sequences.toList(
            runner.run(query, Maps.newHashMap()), Lists.<Result<SelectResultValue>>newArrayList());

    final List<List<Map<String, Object>>> events =
        toEvents(
            new String[] {EventHolder.timestampKey + ":TIME", "foo:NULL", "foo2:NULL"},
            V_0112_0114);

    PagingOffset offset = query.getPagingOffset(QueryRunnerTestHelper.segmentId);
    List<Result<SelectResultValue>> expectedResults =
        toExpected(events, offset.startOffset(), offset.threshold());
    verify(expectedResults, results);
  }

  private Map<String, Integer> toPagingIdentifier(int startDelta, boolean descending) {
    return ImmutableMap.of(
        QueryRunnerTestHelper.segmentId, PagingOffset.toOffset(startDelta, descending));
  }

  private List<List<Map<String, Object>>> toEvents(
      final String[] dimSpecs, final String[]... valueSet) {
    List<List<Map<String, Object>>> events = Lists.newArrayList();
    for (String[] values : valueSet) {
      events.add(
          Lists.newArrayList(
              Iterables.transform(
                  Arrays.asList(values),
                  new Function<String, Map<String, Object>>() {
                    @Override
                    public Map<String, Object> apply(String input) {
                      Map<String, Object> event = Maps.newHashMap();
                      String[] values = input.split("\\t");
                      for (int i = 0; i < dimSpecs.length; i++) {
                        if (dimSpecs[i] == null || i >= dimSpecs.length) {
                          continue;
                        }
                        String[] specs = dimSpecs[i].split(":");
                        event.put(
                            specs[0],
                            specs[1].equals("TIME")
                                ? new DateTime(values[i])
                                : specs[1].equals("FLOAT")
                                    ? Float.valueOf(values[i])
                                    : specs[1].equals("DOUBLE")
                                        ? Double.valueOf(values[i])
                                        : specs[1].equals("LONG")
                                            ? Long.valueOf(values[i])
                                            : specs[1].equals("NULL") ? null : values[i]);
                      }
                      return event;
                    }
                  })));
    }
    return events;
  }

  private List<Result<SelectResultValue>> toExpected(
      List<List<Map<String, Object>>> targets, final int offset, final int threshold) {
    if (offset < 0) {
      targets = Lists.reverse(targets);
    }
    List<Result<SelectResultValue>> expected = Lists.newArrayListWithExpectedSize(targets.size());
    for (List<Map<String, Object>> group : targets) {
      List<EventHolder> holders = Lists.newArrayListWithExpectedSize(threshold);
      int newOffset = offset;
      if (offset < 0) {
        int start = group.size() + offset;
        int end = Math.max(-1, start - threshold);
        for (int i = start; i > end; i--) {
          holders.add(new EventHolder(QueryRunnerTestHelper.segmentId, newOffset--, group.get(i)));
        }
      } else {
        int end = Math.min(group.size(), offset + threshold);
        for (int i = offset; i < end; i++) {
          holders.add(new EventHolder(QueryRunnerTestHelper.segmentId, newOffset++, group.get(i)));
        }
      }
      int lastOffset = holders.isEmpty() ? offset : holders.get(holders.size() - 1).getOffset();
      expected.add(
          new Result(
              new DateTime(group.get(0).get(EventHolder.timestampKey)),
              new SelectResultValue(
                  ImmutableMap.of(QueryRunnerTestHelper.segmentId, lastOffset), holders)));
    }
    return expected;
  }

  private static void verify(
      Iterable<Result<SelectResultValue>> expectedResults,
      Iterable<Result<SelectResultValue>> actualResults) {
    Iterator<Result<SelectResultValue>> expectedIter = expectedResults.iterator();
    Iterator<Result<SelectResultValue>> actualIter = actualResults.iterator();

    while (expectedIter.hasNext()) {
      Result<SelectResultValue> expected = expectedIter.next();
      Result<SelectResultValue> actual = actualIter.next();

      Assert.assertEquals(expected.getTimestamp(), actual.getTimestamp());

      for (Map.Entry<String, Integer> entry :
          expected.getValue().getPagingIdentifiers().entrySet()) {
        Assert.assertEquals(
            entry.getValue(), actual.getValue().getPagingIdentifiers().get(entry.getKey()));
      }

      Iterator<EventHolder> expectedEvts = expected.getValue().getEvents().iterator();
      Iterator<EventHolder> actualEvts = actual.getValue().getEvents().iterator();

      while (expectedEvts.hasNext()) {
        EventHolder exHolder = expectedEvts.next();
        EventHolder acHolder = actualEvts.next();

        Assert.assertEquals(exHolder.getTimestamp(), acHolder.getTimestamp());
        Assert.assertEquals(exHolder.getOffset(), acHolder.getOffset());

        for (Map.Entry<String, Object> ex : exHolder.getEvent().entrySet()) {
          Object actVal = acHolder.getEvent().get(ex.getKey());

          // work around for current II limitations
          if (acHolder.getEvent().get(ex.getKey()) instanceof Double) {
            actVal = ((Double) actVal).floatValue();
          }
          Assert.assertEquals(ex.getValue(), actVal);
        }
      }

      if (actualEvts.hasNext()) {
        throw new ISE("This event iterator should be exhausted!");
      }
    }

    if (actualIter.hasNext()) {
      throw new ISE("This iterator should be exhausted!");
    }
  }
}