Skip to content

Commit

Permalink
Separate old / new format tests, check before running new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmoore committed Dec 13, 2016
1 parent 7879b9f commit 76b5fc6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
import com.basho.riak.client.core.operations.itest.ts.ITestTsBase;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.timeseries.*;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runners.MethodSorters;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -58,11 +55,17 @@ public class ITestTimeSeries extends ITestTsBase

private RiakFuture<Void, String> createTableAsync(final RiakClient client, String tableName) throws InterruptedException
{
final TableDefinition tableDef = new TableDefinition(tableName, GeoCheckinWideTableDefinition.getFullColumnDescriptions());
final TableDefinition tableDef = new TableDefinition(tableName, GeoCheckin_1_5_TableDefinition.getFullColumnDescriptions());

return createTableAsync(client, tableDef);
}

@BeforeClass
public static void SetupCheck()
{
assertTrue(testTs_1_5_Features());
}

@Rule
public ExpectedException thrown= ExpectedException.none();

Expand Down Expand Up @@ -105,7 +108,7 @@ public void test_c_StoringData() throws ExecutionException, InterruptedException
{
RiakClient client = new RiakClient(cluster);

Store store = new Store.Builder(tableName).withRows(rows).build();
Store store = new Store.Builder(tableName).withRows(ts_1_5_rows).build();

RiakFuture<Void, String> execFuture = client.executeAsync(store);

Expand Down Expand Up @@ -158,7 +161,7 @@ public void test_f_QueryingDataWithMinimumPredicate() throws ExecutionException,
assertEquals(8, queryResult.getColumnDescriptionsCopy().size());
assertEquals(1, queryResult.getRowsCount());

assertRowMatches(rows.get(1), queryResult.iterator().next());
assertRowMatches(ts_1_5_rows.get(1), queryResult.iterator().next());
}

@Test
Expand All @@ -179,7 +182,7 @@ public void test_g_QueryingDataWithExtraPredicate() throws ExecutionException, I
assertEquals(8, queryResult.getColumnDescriptionsCopy().size());
assertEquals(1, queryResult.getRowsCount());

assertRowMatches(rows.get(1), queryResult.iterator().next());
assertRowMatches(ts_1_5_rows.get(1), queryResult.iterator().next());
}

@Test
Expand All @@ -200,8 +203,8 @@ public void test_h_QueryingDataAcrossManyQuantum() throws ExecutionException, In
assertEquals(2, queryResult.getRowsCount());

final Iterator<? extends Row> itor = queryResult.iterator();
assertRowMatches(rows.get(1), itor.next());
assertRowMatches(rows.get(2), itor.next());
assertRowMatches(ts_1_5_rows.get(1), itor.next());
assertRowMatches(ts_1_5_rows.get(2), itor.next());
}

@Test
Expand Down Expand Up @@ -256,7 +259,7 @@ public void test_k_TestStoringDataOutOfOrderResultsInError() throws ExecutionExc
@Test
public void test_l_TestFetchingSingleRowsWorks() throws ExecutionException, InterruptedException
{
Row expectedRow = rows.get(7);
Row expectedRow = ts_1_5_rows.get(7);
List<Cell> keyCells = expectedRow.getCellsCopy().stream().limit(3).collect(Collectors.toList());

RiakClient client = new RiakClient(cluster);
Expand Down Expand Up @@ -403,7 +406,7 @@ public void test_z_TestPBCErrorsReturnWhenSecurityIsOn() throws InterruptedExcep

private static List<FullColumnDescription> GetCreatedTableFullDescriptions()
{
return GeoCheckinWideTableDefinition.getFullColumnDescriptions().stream().collect(Collectors.toList());
return GeoCheckin_1_5_TableDefinition.getFullColumnDescriptions().stream().collect(Collectors.toList());
}

private static <T> List<T> toList(Iterator<T> itor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import org.junit.BeforeClass;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Time Series Operation Integration Tests Base
Expand Down Expand Up @@ -46,6 +49,7 @@
public abstract class ITestTsBase extends ITestAutoCleanupBase
{
protected final static String tableName = "GeoCheckin_Wide";
protected final static String tableName_ts_1_5 = "GeoCheckin_Wide_1_5";

protected final static TableDefinition GeoCheckinWideTableDefinition = new TableDefinition(tableName,
Arrays.asList(
Expand All @@ -57,48 +61,75 @@ public abstract class ITestTsBase extends ITestAutoCleanupBase
new FullColumnDescription("weather", ColumnDescription.ColumnType.VARCHAR, false),
new FullColumnDescription("temperature", ColumnDescription.ColumnType.DOUBLE, true),
new FullColumnDescription("uv_index", ColumnDescription.ColumnType.SINT64, true),
new FullColumnDescription("observed", ColumnDescription.ColumnType.BOOLEAN, false),
new FullColumnDescription("sensor_data", ColumnDescription.ColumnType.BLOB, true)
new FullColumnDescription("observed", ColumnDescription.ColumnType.BOOLEAN, false)
)
);

protected final static TableDefinition GeoCheckin_1_5_TableDefinition;

static
{
final LinkedList<FullColumnDescription> geoCheckinColumns =
new LinkedList<>(GeoCheckinWideTableDefinition.getFullColumnDescriptions());
geoCheckinColumns.add(new FullColumnDescription("sensor_data", ColumnDescription.ColumnType.BLOB, true));
GeoCheckin_1_5_TableDefinition = new TableDefinition(tableName, geoCheckinColumns);
}

protected final static long now = 1443806900000L; // "now"
protected final static long fiveMinsInMS = 5L * 60L * 1000L;
protected final static long fiveMinsAgo = now - fiveMinsInMS;
protected final static long tenMinsAgo = fiveMinsAgo - fiveMinsInMS;
protected final static long fifteenMinsAgo = tenMinsAgo - fiveMinsInMS;
protected final static long fifteenMinsInFuture = now + (fiveMinsInMS * 3L);

protected final static List<Row> rows = Arrays.asList(
protected final static List<Row> rows;
protected static final List<Row> ts_1_5_rows;

private static Function<Row,Row> convertToTs1_5Row = x ->
{
final List<Cell> cells = new LinkedList<>(x.getCellsCopy());
cells.add(null);
return new Row(cells);
};

static
{
rows = Arrays.asList(
// "Normal" Data
new Row(new Cell("hash1"), new Cell("user1"), Cell.newTimestamp(fifteenMinsAgo),
new Cell("cloudy"), new Cell(79.0), new Cell(1), new Cell(true), null),
new Cell("cloudy"), new Cell(79.0), new Cell(1), new Cell(true)),

new Row(new Cell("hash1"), new Cell("user1"), Cell.newTimestamp(fiveMinsAgo),
new Cell("sunny"), new Cell(80.5), new Cell(2), new Cell(true), null),
new Cell("sunny"), new Cell(80.5), new Cell(2), new Cell(true)),

new Row(new Cell("hash1"), new Cell("user1"), Cell.newTimestamp(now),
new Cell("sunny"), new Cell(81.0), new Cell(10), new Cell(false), null),
new Cell("sunny"), new Cell(81.0), new Cell(10), new Cell(false)),

// Null Cell row
new Row(new Cell("hash1"), new Cell("user2"), Cell.newTimestamp(fiveMinsAgo),
new Cell("cloudy"), null, null, new Cell(true), null),
new Cell("cloudy"), null, null, new Cell(true)),

// Data for single reads / deletes
new Row(new Cell("hash2"), new Cell("user4"), Cell.newTimestamp(fifteenMinsAgo),
new Cell("rain"), new Cell(79.0), new Cell(2), new Cell(false), null),
new Cell("rain"), new Cell(79.0), new Cell(2), new Cell(false)),

new Row(new Cell("hash2"), new Cell("user4"), Cell.newTimestamp(fiveMinsAgo),
new Cell("wind"), new Cell(50.5), new Cell(3), new Cell(true), null),
new Cell("wind"), new Cell(50.5), new Cell(3), new Cell(true)),

new Row(new Cell("hash2"), new Cell("user4"), Cell.newTimestamp(now),
new Cell("snow"), new Cell(20.0), new Cell(11), new Cell(true), null),


// Data for blob tests
new Row(new Cell("hash2"), new Cell("user4"), Cell.newTimestamp(now + 3),
new Cell("snow"), new Cell(20.0), new Cell(11), new Cell(true), new Cell(new byte[] {0,1,2,3,4,5,6,7}))
);
new Cell("snow"), new Cell(20.0), new Cell(11), new Cell(true)));

final LinkedList<Row> extendedRows = new LinkedList<>();
extendedRows.addAll(rows.stream()
.map(convertToTs1_5Row)
.collect(Collectors.toList()));
// Data for blob tests
extendedRows.add(new Row(new Cell("hash2"), new Cell("user4"), Cell.newTimestamp(now + 3),
new Cell("snow"), new Cell(20.0), new Cell(11), new Cell(true),
new Cell(new byte[] {0,1,2,3,4,5,6,7})));

ts_1_5_rows = extendedRows;
}

@BeforeClass
public static void BeforeClass() throws ExecutionException, InterruptedException
Expand Down Expand Up @@ -178,4 +209,23 @@ protected static QueryResult executeQuery(Query.Builder builder) throws Executio
assertFutureSuccess(future);
return future.get();
}

protected static boolean testTs_1_5_Features()
{
final Namespace ns = new Namespace(tableName_ts_1_5, tableName_ts_1_5);
final FetchBucketPropsOperation fbp = new FetchBucketPropsOperation.Builder(ns).build();

final RiakFuture<FetchBucketPropsOperation.Response, Namespace> execute = cluster.execute(fbp);
try
{
final FetchBucketPropsOperation.Response response = execute.get();
response.getBucketProperties();
}
catch (Exception ex)
{
System.out.println(ex.toString());
return false;
}
return true;
}
}

0 comments on commit 76b5fc6

Please sign in to comment.