Search in sources :

Example 1 with TupleWritable

use of org.apache.crunch.types.writable.TupleWritable in project crunch by cloudera.

the class TupleWritablePartitionerTest method testGetPartition.

@Test
public void testGetPartition() {
    IntWritable intWritable = new IntWritable(3);
    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(3, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
}
Also used : TupleWritable(org.apache.crunch.types.writable.TupleWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 2 with TupleWritable

use of org.apache.crunch.types.writable.TupleWritable in project crunch by cloudera.

the class TupleWritablePartitionerTest method testGetPartition_NegativeHashValue.

@Test
public void testGetPartition_NegativeHashValue() {
    IntWritable intWritable = new IntWritable(-3);
    // Sanity check, if this doesn't work then the premise of this test is wrong
    assertEquals(-3, intWritable.hashCode());
    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(3, tupleWritableParitioner.getPartition(key, NullWritable.get(), 5));
    assertEquals(1, tupleWritableParitioner.getPartition(key, NullWritable.get(), 2));
}
Also used : TupleWritable(org.apache.crunch.types.writable.TupleWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 3 with TupleWritable

use of org.apache.crunch.types.writable.TupleWritable in project crunch by cloudera.

the class TupleWritablePartitionerTest method testGetPartition_IntegerMinValue.

@Test
public void testGetPartition_IntegerMinValue() {
    IntWritable intWritable = new IntWritable(Integer.MIN_VALUE);
    // Sanity check, if this doesn't work then the premise of this test is wrong
    assertEquals(Integer.MIN_VALUE, intWritable.hashCode());
    TupleWritable key = new TupleWritable(new Writable[] { intWritable });
    assertEquals(0, tupleWritableParitioner.getPartition(key, NullWritable.get(), Integer.MAX_VALUE));
}
Also used : TupleWritable(org.apache.crunch.types.writable.TupleWritable) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Aggregations

TupleWritable (org.apache.crunch.types.writable.TupleWritable)3 IntWritable (org.apache.hadoop.io.IntWritable)3 Test (org.junit.Test)3