Search in sources :

Example 11 with Employee

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;
}
Also used : Employee(org.apache.gora.examples.generated.Employee) Utf8(org.apache.avro.util.Utf8)

Example 12 with 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));
    }
}
Also used : Employee(org.apache.gora.examples.generated.Employee) HashMap(java.util.HashMap) Metadata(org.apache.gora.examples.generated.Metadata) Utf8(org.apache.avro.util.Utf8) Test(org.junit.Test)

Example 13 with Employee

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();
}
Also used : Employee(org.apache.gora.examples.generated.Employee)

Example 14 with Employee

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;
}
Also used : Employee(org.apache.gora.examples.generated.Employee)

Example 15 with 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);
}
Also used : Employee(org.apache.gora.examples.generated.Employee)

Aggregations

Employee (org.apache.gora.examples.generated.Employee)23 Utf8 (org.apache.avro.util.Utf8)11 Test (org.junit.Test)7 WebPage (org.apache.gora.examples.generated.WebPage)5 Metadata (org.apache.gora.examples.generated.Metadata)2 Configuration (org.apache.hadoop.conf.Configuration)2 HashMap (java.util.HashMap)1 GoraInfinispanTestDriver (org.apache.gora.infinispan.GoraInfinispanTestDriver)1 Before (org.junit.Before)1