use of org.apache.gora.examples.generated.Employee in project gora by apache.
the class DataStoreTestUtil method createEmployee.
public static <K> Employee createEmployee() throws Exception {
Employee employee = Employee.newBuilder().build();
employee.setName(new Utf8("Random Joe"));
employee.setDateOfBirth(System.currentTimeMillis() - 20L * YEAR_IN_MS);
employee.setSalary(100000);
employee.setSsn(new Utf8("101010101010"));
return employee;
}
use of org.apache.gora.examples.generated.Employee in project gora by apache.
the class TestHBaseByteInterface method testEncodingDecoding.
@Test
public void testEncodingDecoding() throws Exception {
for (int i = 0; i < 1000; i++) {
//employer
CharSequence name = new Utf8("john");
long dateOfBirth = System.currentTimeMillis();
int salary = 1337;
CharSequence ssn = new Utf8(String.valueOf(RANDOM.nextLong()));
Employee e = Employee.newBuilder().build();
e.setName(name);
e.setDateOfBirth(dateOfBirth);
e.setSalary(salary);
e.setSsn(ssn);
byte[] employerBytes = HBaseByteInterface.toBytes(e, Employee.SCHEMA$);
Employee e2 = (Employee) HBaseByteInterface.fromBytes(Employee.SCHEMA$, employerBytes);
assertEquals(name, e2.getName());
assertEquals(dateOfBirth, e2.getDateOfBirth().longValue());
assertEquals(salary, e2.getSalary().intValue());
assertEquals(ssn, e2.getSsn());
//metadata
CharSequence key = new Utf8("theKey");
CharSequence value = new Utf8("theValue " + RANDOM.nextLong());
HashMap<CharSequence, CharSequence> data = new HashMap<>();
data.put(key, value);
Metadata m = Metadata.newBuilder().build();
m.setData(data);
byte[] datumBytes = HBaseByteInterface.toBytes(m, Metadata.SCHEMA$);
Metadata m2 = (Metadata) HBaseByteInterface.fromBytes(Metadata.SCHEMA$, datumBytes);
assertEquals(value, m2.getData().get(key));
}
}
use of org.apache.gora.examples.generated.Employee in project gora by apache.
the class Utils method populateEmployeeStore.
public static <T extends CharSequence> void populateEmployeeStore(DataStore<T, Employee> dataStore, int n) {
for (int i = 0; i < n; i++) {
Employee e = createEmployee(i);
dataStore.put((T) e.getSsn(), e);
}
dataStore.flush();
}
use of org.apache.gora.examples.generated.Employee in project gora by apache.
the class Utils method createEmployee.
public static Employee createEmployee(int i) {
Employee employee = Employee.newBuilder().build();
employee.setSsn(Long.toString(i));
employee.setName(Long.toString(rand.nextLong()));
employee.setDateOfBirth(rand.nextLong() - 20L * YEAR_IN_MS);
employee.setSalary(rand.nextInt());
return employee;
}
use of org.apache.gora.examples.generated.Employee in project gora by apache.
the class DataStoreTestUtil method testGetEmployeeRecursive.
public static void testGetEmployeeRecursive(DataStore<String, Employee> dataStore) throws Exception {
Employee employee = DataStoreTestUtil.createEmployee();
Employee boss = DataStoreTestUtil.createBoss();
employee.setBoss(boss);
String ssn = employee.getSsn().toString();
dataStore.put(ssn, employee);
dataStore.flush();
Employee after = dataStore.get(ssn, AvroUtils.getSchemaFieldNames(Employee.SCHEMA$));
assertEqualEmployeeObjects(employee, after);
}
Aggregations