/* * Licensed to STRATIO (C) under one or more contributor license agreements. * See the NOTICE file distributed with this work for additional information * regarding copyright ownership. The STRATIO (C) 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 com.stratio.cassandra.lucene.testsAT.varia; import com.stratio.cassandra.lucene.testsAT.BaseAT; import com.stratio.cassandra.lucene.testsAT.util.CassandraUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import static com.stratio.cassandra.lucene.builder.Builder.field; import static com.stratio.cassandra.lucene.builder.Builder.integerMapper; /** * @author Andres de la Pena <adelapena@stratio.com> */ @RunWith(JUnit4.class) public class SortWithWideRowsAT extends BaseAT { private static CassandraUtils utils; @BeforeClass public static void before() { utils = CassandraUtils.builder("sort_with_wide_rows") .withPartitionKey("pk") .withClusteringKey("ck") .withColumn("pk", "int", integerMapper().sorted(true)) .withColumn("ck", "int", integerMapper().sorted(true)) .withColumn("rc", "int", integerMapper().sorted(true)) .build() .createKeyspace() .createTable() .createIndex(); int count = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { utils.insert(new String[]{"pk", "ck", "rc"}, new Object[]{i, j, count++}); } } } @AfterClass public static void after() { utils.dropIndex().dropTable().dropKeyspace(); } @Test public void sortAsc() { utils.sort(field("rc").reverse(false)).limit(3).check("rc", Integer.class, 0, 1, 2); } @Test public void sortDesc() { utils.sort(field("rc").reverse(true)).limit(3).check("rc", Integer.class, 99, 98, 97); } @Test public void sortPartitionAsc() { utils.sort(field("rc").reverse(false)).andEq("pk", 1).limit(3).check("rc", Integer.class, 10, 11, 12); } @Test public void sortPartitionDesc() { utils.sort(field("rc").reverse(true)).andEq("pk", 1).limit(3).check("rc", Integer.class, 19, 18, 17); } @Test public void sortPartitionSliceAsc() { utils.sort(field("rc").reverse(false)) .andEq("pk", 1) .andGt("ck", 1) .limit(3) .check("rc", Integer.class, 12, 13, 14); } @Test public void sortPartitionSliceDesc() { utils.sort(field("rc").reverse(true)) .andEq("pk", 1) .andLt("ck", 7) .limit(3) .check("rc", Integer.class, 16, 15, 14); } @Test public void sortTokenRangeAsc() { utils.sort(field("rc").reverse(false)).andGt("token(pk)", 0).limit(3).check("rc", Integer.class, 30, 31, 32); } @Test public void sortTokenRangeDesc() { utils.sort(field("rc").reverse(true)).andLt("token(pk)", 0).limit(3).check("rc", Integer.class, 89, 88, 87); } }