Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
arman-ddl committed Sep 5, 2024
1 parent 52b7ee4 commit 4649a1a
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.engine.table.impl;

import io.deephaven.api.SortColumn;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.BasicDataIndex;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.impl.AbstractTableLocation;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionByte;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionChar;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionDouble;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionFloat;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionInt;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionLong;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionObject;
import io.deephaven.engine.table.impl.sources.regioned.ColumnRegionShort;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public final class DummyTableLocation extends AbstractTableLocation {

public DummyTableLocation(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
super(tableKey, tableLocationKey, false);
}

@Override
public void refresh() {}

@Override
public @NotNull List<SortColumn> getSortedColumns() {
return List.of();
}

@Override
@NotNull
public List<String[]> getDataIndexColumns() {
return List.of();
}

@Override
public boolean hasDataIndex(@NotNull final String... columns) {
return false;
}

@NotNull
@Override
protected ColumnLocation makeColumnLocation(@NotNull final String name) {
return new ColumnLocation() {
@NotNull
@Override
public TableLocation getTableLocation() {
return DummyTableLocation.this;
}

@NotNull
@Override
public String getName() {
return name;
}

@Override
public boolean exists() {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionChar<Values> makeColumnRegionChar(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionByte<Values> makeColumnRegionByte(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionShort<Values> makeColumnRegionShort(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionInt<Values> makeColumnRegionInt(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionLong<Values> makeColumnRegionLong(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionFloat<Values> makeColumnRegionFloat(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionDouble<Values> makeColumnRegionDouble(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public <TYPE> ColumnRegionObject<TYPE, Values> makeColumnRegionObject(
@NotNull final ColumnDefinition<TYPE> columnDefinition) {
throw new UnsupportedOperationException();
}

};
}

@Override
@Nullable
public BasicDataIndex loadDataIndex(@NotNull final String... columns) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//
package io.deephaven.engine.table.impl;

import io.deephaven.api.SortColumn;
import io.deephaven.api.filter.Filter;
import io.deephaven.base.verify.Assert;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.primitive.iterator.CloseableIterator;
import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.table.*;
Expand All @@ -17,17 +15,11 @@
import io.deephaven.engine.testutil.TstUtils;
import io.deephaven.engine.testutil.junit4.EngineCleanup;
import io.deephaven.time.DateTimeUtils;
import io.deephaven.engine.table.impl.locations.ColumnLocation;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.impl.*;
import io.deephaven.engine.table.impl.select.MatchFilter;
import io.deephaven.engine.table.impl.select.WhereFilter;
import io.deephaven.engine.table.impl.sources.regioned.*;
import io.deephaven.engine.rowset.RowSetFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -135,109 +127,4 @@ public void testEverything() {

TstUtils.assertTableEquals(expected.selectDistinct(), result.selectDistinct());
}

private static final class DummyTableLocation extends AbstractTableLocation {

private DummyTableLocation(@NotNull final TableKey tableKey,
@NotNull final TableLocationKey tableLocationKey) {
super(tableKey, tableLocationKey, false);
}

@Override
public void refresh() {}

@Override
public @NotNull List<SortColumn> getSortedColumns() {
return List.of();
}

@Override
@NotNull
public List<String[]> getDataIndexColumns() {
return List.of();
}

@Override
public boolean hasDataIndex(@NotNull final String... columns) {
return false;
}

@NotNull
@Override
protected ColumnLocation makeColumnLocation(@NotNull final String name) {
return new ColumnLocation() {
@NotNull
@Override
public TableLocation getTableLocation() {
return DummyTableLocation.this;
}

@NotNull
@Override
public String getName() {
return name;
}

@Override
public boolean exists() {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionChar<Values> makeColumnRegionChar(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionByte<Values> makeColumnRegionByte(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionShort<Values> makeColumnRegionShort(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionInt<Values> makeColumnRegionInt(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionLong<Values> makeColumnRegionLong(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionFloat<Values> makeColumnRegionFloat(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public ColumnRegionDouble<Values> makeColumnRegionDouble(
@NotNull final ColumnDefinition<?> columnDefinition) {
throw new UnsupportedOperationException();
}

@Override
public <TYPE> ColumnRegionObject<TYPE, Values> makeColumnRegionObject(
@NotNull final ColumnDefinition<TYPE> columnDefinition) {
throw new UnsupportedOperationException();
}

};
}

@Override
@Nullable
public BasicDataIndex loadDataIndex(@NotNull final String... columns) {
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.engine.table.impl.locations.impl;

import io.deephaven.engine.table.impl.DummyTableLocation;
import io.deephaven.engine.table.impl.locations.TableDataException;
import io.deephaven.engine.table.impl.locations.TableDataService;
import io.deephaven.engine.table.impl.locations.TableKey;
import io.deephaven.engine.table.impl.locations.TableLocation;
import io.deephaven.engine.table.impl.locations.TableLocationKey;
import io.deephaven.engine.table.impl.locations.TableLocationProvider;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;

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

public class TestTableDataService {
@Test
public void testGetRawTableDataService() {
final Map<String, Comparable<?>> partitions1 = new HashMap<>();
partitions1.put("Part", "A");
final Map<String, Comparable<?>> partitions2 = new HashMap<>();
partitions2.put("Part", "B");
final Map<String, Comparable<?>> partitions3 = new HashMap<>();
partitions3.put("Part", "C");

TableLocationKey tlk1 = new SimpleTableLocationKey(partitions1);
TableLocationKey tlk2 = new SimpleTableLocationKey(partitions2);
TableLocationKey tlk3 = new SimpleTableLocationKey(partitions3);

// No table location overlap
final CompositeTableDataService ctds1 =
new CompositeTableDataService("ctds1", new DummyServiceSelector(tlk1, tlk2));
Assert.assertNotNull(ctds1.getRawTableLocationProvider(StandaloneTableKey.getInstance(), tlk1));
Assert.assertNull(ctds1.getRawTableLocationProvider(StandaloneTableKey.getInstance(), tlk3));

// Table location overlap
final CompositeTableDataService ctds2 =
new CompositeTableDataService("ctds2", new DummyServiceSelector(tlk1, tlk1));
Assert.assertThrows(TableDataException.class,
() -> ctds2.getRawTableLocationProvider(StandaloneTableKey.getInstance(), tlk1));
Assert.assertNull(ctds2.getRawTableLocationProvider(StandaloneTableKey.getInstance(), tlk3));
}

private static class DummyTableDataService extends AbstractTableDataService {
final TableLocation tableLocation;

private DummyTableDataService(@NotNull final String name, @NotNull final TableLocation tableLocation) {
super(name);
this.tableLocation = tableLocation;
}

@Override
@NotNull
protected TableLocationProvider makeTableLocationProvider(@NotNull TableKey tableKey) {
return new SingleTableLocationProvider(tableLocation);
}
}

private static class DummyServiceSelector implements CompositeTableDataService.ServiceSelector {
final TableDataService[] tableDataServices;

private DummyServiceSelector(final TableLocationKey tlk1, final TableLocationKey tlk2) {
final FilteredTableDataService.LocationKeyFilter dummyFilter = (tlk) -> true;
tableDataServices = new TableDataService[] {
new FilteredTableDataService(new DummyTableDataService("dummyTds1",
new DummyTableLocation(StandaloneTableKey.getInstance(), tlk1)), dummyFilter),
new FilteredTableDataService(new DummyTableDataService("dummyTds2",
new DummyTableLocation(StandaloneTableKey.getInstance(), tlk2)), dummyFilter)
};
// Init table locations
tableDataServices[0].getTableLocationProvider(StandaloneTableKey.getInstance())
.getTableLocationIfPresent(tlk1);
tableDataServices[1].getTableLocationProvider(StandaloneTableKey.getInstance())
.getTableLocationIfPresent(tlk2);
}

@Override
public TableDataService[] call(@NotNull TableKey tableKey) {
return tableDataServices;
}

@Override
public void resetServices() {
throw new UnsupportedOperationException();
}

@Override
public void resetServices(@NotNull TableKey key) {
throw new UnsupportedOperationException();
}
}
}

0 comments on commit 4649a1a

Please sign in to comment.