@Test public void testJavaSerializableSerde() throws Exception { Integer integer = 42; testSerializeDeserialize(integer); }
@Test public void testReadFullyBufferLimit() throws IOException { for(int i=-2; i<=2; i++) { byte[] bytes = new byte[IOUtils.BUFFER_SIZE + i]; for(int j=0; j<bytes.length; j++) { bytes[j] = (byte)j; } ByteArrayInputStream is = new ByteArrayInputStream(bytes); byte[] readBytes = IOUtils.readFully(is); assertByteArrayEquals(bytes, readBytes); } }
@Test public void testReadWriteNullFieldsInfo() throws IOException { Integer n = null; //null Integer nn = 42; //not null testNullFieldsWith(nn); testNullFieldsWith(n); testNullFieldsWith(n, nn); testNullFieldsWith(nn, n); testNullFieldsWith(nn, n, nn, n); testNullFieldsWith(nn, n, nn, n, n, n, nn, nn, nn, n, n); }
@Test public void testWritableSerde() throws Exception { Text text = new Text("foo goes to a bar to get some buzz"); testSerializeDeserialize(text); }
@Test public void testReadWriteStringArray() throws Exception { for(int i=0; i<STRING_ARRAY_MAX_LENGTH; i++) { String[] arr = new String[i]; for(int j=0; j<i; j++) { arr[j] = String.valueOf(j); } testSerializeDeserialize(new StringArrayWrapper(arr)); } }
@Test public void testReadWrite2() throws Exception { query.setLimit(1000); query.setTimeRange(0, System.currentTimeMillis()); TestIOUtils.testSerializeDeserialize(query); }
/** * Creates an Employee object in-memory setting several fields to dirty. * Asserts that it can be serialized and * deserialzed without loosing data. We do this by asserting * what we get 'before' and 'after' (de)serialization processes. * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testSerdeEmployee() throws Exception { MemStore<String, Employee> store = DataStoreFactory.getDataStore( MemStore.class, String.class, Employee.class, new Configuration()); Employee employee = DataStoreTestUtil.createEmployee(); TestIOUtils.testSerializeDeserialize(employee); }
@Test public void testReadWriteBoolArray() throws Exception { boolean[][] patterns = { {true}, {false}, {true, false}, {false, true}, {true, false, true}, {false, true, false}, {false, true, false, false, true, true, true}, {false, true, false, false, true, true, true, true}, {false, true, false, false, true, true, true, true, false}, }; for(int i=0; i<BOOL_ARRAY_MAX_LENGTH; i++) { for(int j=0; j<patterns.length; j++) { boolean[] arr = new boolean[i]; for(int k=0; k<i; k++) { arr[k] = patterns[j][k % patterns[j].length]; } testSerializeDeserialize(new BoolArrayWrapper(arr)); } } }
/** * Creates an Employee object but only sets one field as dirty. * We then do (de)serialization and check 'before' and 'after' * states. * @throws Exception */ @Test public void testSerdeEmployeeOneField() throws Exception { Employee employee = Employee.newBuilder().build(); employee.setSsn(new Utf8("11111")); TestIOUtils.testSerializeDeserialize(employee); }
@Test public void testReadWrite() throws Exception { query.setFields(FIELDS); query.setKeyRange(START_KEY, END_KEY); TestIOUtils.testSerializeDeserialize(query); assertNotNull(query.getDataStore()); }
/** * Creates an Employee object setting only two fields as dirty. * We then do (de)serialization and check 'before' and 'after' * states. * @throws Exception */ @Test public void testSerdeEmployeeTwoFields() throws Exception { Employee employee = Employee.newBuilder().build(); employee.setSsn(new Utf8("11111")); employee.setSalary(100); TestIOUtils.testSerializeDeserialize(employee); }
@Test public void testQueryMarshability() throws Exception { Utils.populateEmployeeStore(employeeStore, 100); InfinispanQuery<String,Employee> query = new InfinispanQuery<>(employeeDataStore); query.setFields("field"); query.setLimit(1); query.setOffset(1); query.build(); TestIOUtils.testSerializeDeserialize(query); }
/** * Creates an WebPage object in-memory setting several fields to dirty. * Run a query over the persistent data. * Asserts that the results can be serialized and * deserialzed without loosing data. We do this by asserting * what we get 'before' and 'after' (de)serialization processes. * Also simple assertion for equal number of URL's in WebPage * and results. * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testSerdeWebPage() throws Exception { MemStore<String, WebPage> store = DataStoreFactory.getDataStore( MemStore.class, String.class, WebPage.class, new Configuration()); WebPageDataCreator.createWebPageData(store); Result<String, WebPage> result = store.newQuery().execute(); int i = 0; while (result.next()) { WebPage page = result.get(); TestIOUtils.testSerializeDeserialize(page); i++; } assertEquals(WebPageDataCreator.URLS.length, i); }
/** * Creates multiple WebPage objects setting several fields to dirty. * Asserts that the data can be serialized and * deserialzed without loosing data. We do this by asserting * what we get 'before' and 'after' (de)serialization processes. * @throws Exception */ @Test public void testSerdeMultipleWebPages() throws Exception { WebPage page1 = WebPage.newBuilder().build(); WebPage page2 = WebPage.newBuilder().build(); WebPage page3 = WebPage.newBuilder().build(); page1.setUrl(new Utf8("foo")); page2.setUrl(new Utf8("baz")); page3.setUrl(new Utf8("bar")); page1.setParsedContent(new ArrayList<CharSequence>()); page1.getParsedContent().add(new Utf8("coo")); page2.setOutlinks(new HashMap<CharSequence, CharSequence>()); page2.getOutlinks().put(new Utf8("a"), new Utf8("b")); TestIOUtils.testSerializeDeserialize(page1, page2, page3); }