Skip to content

Commit

Permalink
Get some tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Helmling committed Dec 18, 2009
1 parent ccce2b1 commit 154321d
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 44 deletions.
7 changes: 6 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<property name="dist.dir" value="${basedir}/dist" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="src.dir" value="${basedir}/src/java" />
<property name="test.src.dir" value="${basedir}/test/java" />

<path id="project.class.path">
<fileset dir="${lib.dir}" includes="**/*.jar" />
Expand All @@ -29,7 +30,11 @@

<!-- build the source -->
<target name="compile" depends="init">
<javac debug="yes" srcdir="${src.dir}" destdir="${build.dir}" deprecation="true" source="1.5" nowarn="true" >
<javac debug="yes" srcdir="${src.dir}" destdir="${build.dir}" deprecation="true" source="1.6" nowarn="true" >
<classpath refid="project.class.path"/>
<compilerarg line="-Xmaxerrs 10000"/>
</javac>
<javac debug="yes" srcdir="${test.src.dir}" destdir="${build.dir}" deprecation="true" source="1.6" nowarn="true" >
<classpath refid="project.class.path"/>
<compilerarg line="-Xmaxerrs 10000"/>
</javac>
Expand Down
6 changes: 6 additions & 0 deletions conf/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
log4j.rootCategory=INFO, R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=beeno.log
log4j.appender.R.DatePattern='.'yyyy-MM-dd
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
Binary file added lib/commons-logging-api-1.0.4.jar
Binary file not shown.
12 changes: 6 additions & 6 deletions src/java/meetup/beeno/Criteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.ArrayList;
import java.util.List;

import meetup.beeno.filter.ColumnRowFilter;
import meetup.beeno.filter.ColumnMatchFilter;
import meetup.beeno.filter.WhileMatchFilter;
import meetup.beeno.util.IOUtil;
import meetup.beeno.util.PBUtil;
Expand Down Expand Up @@ -91,11 +91,11 @@ public static Expression or(List<Expression> expr) {
}

public static Expression eq(String prop, Object val) {
return new PropertyComparison(prop, val, ColumnRowFilter.CompareOp.EQUAL);
return new PropertyComparison(prop, val, ColumnMatchFilter.CompareOp.EQUAL);
}

public static Expression ne(String prop, Object val) {
return new PropertyComparison(prop, val, ColumnRowFilter.CompareOp.NOT_EQUAL);
return new PropertyComparison(prop, val, ColumnMatchFilter.CompareOp.NOT_EQUAL);
}

public static abstract class Expression implements Externalizable {
Expand Down Expand Up @@ -146,13 +146,13 @@ public String toString() {

public static class PropertyComparison extends PropertyExpression {

private ColumnRowFilter.CompareOp op = null;
private ColumnMatchFilter.CompareOp op = null;

public PropertyComparison() {
// for Externalizable
}

public PropertyComparison(String prop, Object val, ColumnRowFilter.CompareOp op) {
public PropertyComparison(String prop, Object val, ColumnMatchFilter.CompareOp op) {
super(prop, val);
this.op = op;
}
Expand All @@ -169,7 +169,7 @@ public Filter getFilter(EntityMetadata.EntityInfo entityInfo) throws HBaseExcept
log.debug(String.format("PropertyComparison(%s, %s, %s): Creating ColumnRowFilter, column=%s",
this.property, this.value, this.op.toString(), mapping.getFieldName()));
}
return new ColumnRowFilter(Bytes.toBytes(mapping.getFieldName()),
return new ColumnMatchFilter(Bytes.toBytes(mapping.getFieldName()),
this.op,
PBUtil.toBytes(this.value),
true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
import org.apache.hadoop.io.ObjectWritable;

/**
* This filter is used to filter based on the value of a given column. It takes
Expand All @@ -38,7 +35,7 @@
* a long and then compare it to a fixed long value, then you can pass in your
* own comparator instead.
*/
public class ColumnRowFilter implements Filter {
public class ColumnMatchFilter implements Filter {

/** Comparison operators. */
public enum CompareOp {
Expand All @@ -59,12 +56,11 @@ public enum CompareOp {
private byte[] columnName;
private CompareOp compareOp;
private byte[] value;
private WritableByteArrayComparable comparator;
private boolean filterIfColumnMissing;
private boolean columnSeen = false;
private boolean columnFiltered = false;

public ColumnRowFilter() {
public ColumnMatchFilter() {
// for Writable
}

Expand All @@ -78,7 +74,7 @@ public ColumnRowFilter() {
* @param value
* value to compare column values against
*/
public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
public ColumnMatchFilter( final byte[] columnName, final CompareOp compareOp,
final byte[] value ) {
this(columnName, compareOp, value, true);
}
Expand All @@ -95,7 +91,7 @@ public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
* @param filterIfColumnMissing
* if true then we will filter rows that don't have the column.
*/
public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
public ColumnMatchFilter( final byte[] columnName, final CompareOp compareOp,
final byte[] value, boolean filterIfColumnMissing ) {
this.columnName = columnName;
this.compareOp = compareOp;
Expand All @@ -113,9 +109,8 @@ public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
* @param comparator
* Comparator to use.
*/
public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
final WritableByteArrayComparable comparator ) {
this(columnName, compareOp, comparator, true);
public ColumnMatchFilter( final byte[] columnName, final CompareOp compareOp ) {
this(columnName, compareOp, true);
}

/**
Expand All @@ -130,12 +125,10 @@ public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
* @param filterIfColumnMissing
* if true then we will filter rows that don't have the column.
*/
public ColumnRowFilter( final byte[] columnName, final CompareOp compareOp,
final WritableByteArrayComparable comparator,
public ColumnMatchFilter( final byte[] columnName, final CompareOp compareOp,
boolean filterIfColumnMissing ) {
this.columnName = columnName;
this.compareOp = compareOp;
this.comparator = comparator;
this.filterIfColumnMissing = filterIfColumnMissing;
}

Expand All @@ -159,12 +152,7 @@ public Filter.ReturnCode filterKeyValue( KeyValue v ) {

private boolean filterColumnValue( final byte[] data ) {
int compareResult;
if (comparator != null) {
compareResult = comparator.compareTo(data);
}
else {
compareResult = compare(value, data);
}
compareResult = compare(value, data);

switch (compareOp) {
case LESS:
Expand Down Expand Up @@ -222,8 +210,6 @@ public void readFields( final DataInput in ) throws IOException {
}
columnName = Bytes.readByteArray(in);
compareOp = CompareOp.valueOf(in.readUTF());
comparator = (WritableByteArrayComparable) ObjectWritable.readObject(
in, new HBaseConfiguration());
filterIfColumnMissing = in.readBoolean();
}

Expand All @@ -237,8 +223,6 @@ public void write( final DataOutput out ) throws IOException {
}
Bytes.writeByteArray(out, columnName);
out.writeUTF(compareOp.name());
ObjectWritable.writeObject(out, comparator,
WritableByteArrayComparable.class, new HBaseConfiguration());
out.writeBoolean(filterIfColumnMissing);
}

Expand Down
196 changes: 196 additions & 0 deletions test/java/meetup/beeno/TestEntities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package meetup.beeno;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import meetup.beeno.HBaseEntity;
import meetup.beeno.HIndex;
import meetup.beeno.HProperty;
import meetup.beeno.HRowKey;

/**
* Collection of sample entity mappings for testing.
*
* @author garyh
*
*/
public class TestEntities {
/**
* Simple, happy path entity with all the right annotations
* @author garyh
*
*/
@HBaseEntity(name="test_simple")
public static class SimpleEntity {
String id;
String stringProperty;
int intProperty;
float floatProperty;
double doubleProperty;
long longProperty;

public SimpleEntity() {
}

public SimpleEntity(String id) {
this.id = id;
}

public SimpleEntity(String id,
String stringProp,
int intProp,
float floatProp,
double doubleProp,
long longProp) {
this.id = id;
this.stringProperty = stringProp;
this.intProperty = intProp;
this.floatProperty = floatProp;
this.doubleProperty = doubleProp;
this.longProperty = longProp;
}

@HRowKey
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }

@HProperty(family="props", name="stringcol")
public String getStringProperty() { return stringProperty; }
public void setStringProperty( String stringProperty ) { this.stringProperty = stringProperty; }

@HProperty(family="props", name="intcol")
public int getIntProperty() { return intProperty; }
public void setIntProperty( int intProperty ) { this.intProperty = intProperty; }

@HProperty(family="props", name="floatcol")
public float getFloatProperty() { return floatProperty; }
public void setFloatProperty( float floatProperty ) { this.floatProperty = floatProperty; }

@HProperty(family="props", name="doublecol")
public double getDoubleProperty() { return doubleProperty; }
public void setDoubleProperty( double doubleProperty ) { this.doubleProperty = doubleProperty; }

@HProperty(family="props", name="longcol")
public long getLongProperty() { return longProperty; }
public void setLongProperty( long longProperty ) { this.longProperty = longProperty; }
}

/**
* More complex entity class containing mapped collections
* @author garyh
*/
@HBaseEntity(name="test_complex")
public static class ComplexEntity {
String id;
List<String> stringList = new ArrayList<String>();
Set<Integer> intSet = new HashSet<Integer>();
Map<String,String> extendedMap = new HashMap<String,String>();

public ComplexEntity() {}

public ComplexEntity(String id) {
this.id = id;
}

public ComplexEntity(String id, List<String> strings, Set<Integer> ints) {
this.id = id;
this.stringList = strings;
this.intSet = ints;
}

@HRowKey
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }

@HProperty(family="props", name="strings", type="string")
public List<String> getStringList() { return this.stringList; }
public void setStringList(List<String> list) { this.stringList = list; }

@HProperty(family="props", name="ints", type="int_type")
public Set<Integer> getIntSet() { return this.intSet; }
public void setIntSet(Set<Integer> set) { this.intSet = set; }

@HProperty(family="extended", name="*", type="string")
public Map<String, String> getExtendedProps() { return this.extendedMap; }
public void setExtendedProps(Map<String,String> props) { this.extendedMap = props; }
}

@HBaseEntity(name="test_nokey")
public static class NoKeyEntity {
String prop1;

@HProperty(family="props", name="prop1")
public String getProp1() { return this.prop1; }
public void setProp1(String prop) { this.prop1 = prop; }
}

@HBaseEntity(name="test_dupekey")
public static class DupeKeyEntity {
String id1;
String id2;

@HRowKey
public String getId1() { return this.id1; }
@HRowKey
public String getId2() { return this.id2; }
}

@HBaseEntity(name="test_dupefield")
public static class DupeFieldEntity {
String id;
String prop1;
String prop2;

@HRowKey
public String getId() { return this.id; }
@HProperty(family="info", name="col1")
public String getProp1() { return this.prop1; }
@HProperty(family="info", name="col1")
public String getProp2() { return this.prop2; }
}

/**
* Simple, happy path entity with all the right annotations
* @author garyh
*
*/
@HBaseEntity(name="test_indexed")
public static class IndexedEntity {
String id;
String stringProperty;
long timestamp;

public IndexedEntity() {
}

public IndexedEntity(String id) {
this.id = id;
}

public IndexedEntity(String id,
String stringProp,
long timestamp) {
this.id = id;
this.stringProperty = stringProp;
this.timestamp = timestamp;
}

@HRowKey
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }

@HProperty(family="props", name="stringcol",
indexes = { @HIndex(extra_cols={"props:tscol"}) } )
public String getStringProperty() { return stringProperty; }
public void setStringProperty( String stringProperty ) { this.stringProperty = stringProperty; }

@HProperty(family="props", name="tscol")
public long getTimestamp() { return timestamp; }
public void setTimestamp( long ts ) { this.timestamp = ts; }
}
}
Loading

0 comments on commit 154321d

Please sign in to comment.