Search in sources :

Example 1 with Person

use of io.paperdb.testdata.Person in project Paper by pilgr.

the class DataTest method testPutPOJO.

@Test
public void testPutPOJO() {
    final Person person = genPerson(new Person(), 1);
    Paper.book().write("profile", person);
    final Person savedPerson = Paper.book().read("profile");
    assertThat(savedPerson).isEqualTo(person);
    assertThat(savedPerson).isNotSameAs(person);
}
Also used : TestDataGenerator.genPerson(io.paperdb.testdata.TestDataGenerator.genPerson) Person(io.paperdb.testdata.Person) Test(org.junit.Test)

Example 2 with Person

use of io.paperdb.testdata.Person in project Paper by pilgr.

the class MultiThreadTest method startWritingLargeDataSetInSeparateThread.

@NonNull
private CountDownLatch startWritingLargeDataSetInSeparateThread(@SuppressWarnings("SameParameterValue") final String key) throws InterruptedException {
    final CountDownLatch writeStartLatch = new CountDownLatch(1);
    final CountDownLatch writeFinishLatch = new CountDownLatch(1);
    new Thread() {

        final List<Person> dataset = TestDataGenerator.genPersonList(10000);

        @Override
        public void run() {
            Log.d(TAG, "write '" + key + "': start");
            writeStartLatch.countDown();
            Paper.book().write(key, dataset);
            Log.d(TAG, "write '" + key + "': finish");
            writeFinishLatch.countDown();
        }
    }.start();
    writeStartLatch.await(5, TimeUnit.SECONDS);
    // A small delay is required to let writer thread start writing data and acquire a lock
    Thread.sleep(100);
    return writeFinishLatch;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Person(io.paperdb.testdata.Person) NonNull(androidx.annotation.NonNull)

Example 3 with Person

use of io.paperdb.testdata.Person in project Paper by pilgr.

the class MultiThreadTest method getInsertRunnable.

private Runnable getInsertRunnable() {
    return new Runnable() {

        @Override
        public void run() {
            int size = new Random().nextInt(200);
            final List<Person> inserted100 = TestDataGenerator.genPersonList(size);
            Paper.book().write("persons", inserted100);
        }
    };
}
Also used : Random(java.util.Random) Person(io.paperdb.testdata.Person)

Example 4 with Person

use of io.paperdb.testdata.Person in project Paper by pilgr.

the class DataTest method testPutPOJO.

@Test
public void testPutPOJO() {
    final Person person = genPerson(new Person(), 1);
    Paper.put("profile", person);
    final Person savedPerson = Paper.get("profile");
    assertThat(savedPerson).isEqualTo(person);
    assertThat(savedPerson).isNotSameAs(person);
}
Also used : TestDataGenerator.genPerson(io.paperdb.testdata.TestDataGenerator.genPerson) Person(io.paperdb.testdata.Person) Test(org.junit.Test)

Aggregations

Person (io.paperdb.testdata.Person)4 TestDataGenerator.genPerson (io.paperdb.testdata.TestDataGenerator.genPerson)2 Test (org.junit.Test)2 NonNull (androidx.annotation.NonNull)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1