@Override public void run() { try { source.run(ctx); } catch (Throwable t) { error[0] = t; } } };
@Test public void testStrings() { try { String[] data = { "Oh", "boy", "what", "a", "show", "!"}; FromElementsFunction<String> source = new FromElementsFunction<String>( BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), data); List<String> result = new ArrayList<String>(); source.run(new ListSourceContext<String>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testNonJavaSerializableType() { try { MyPojo[] data = { new MyPojo(1, 2), new MyPojo(3, 4), new MyPojo(5, 6) }; FromElementsFunction<MyPojo> source = new FromElementsFunction<MyPojo>( TypeExtractor.getForClass(MyPojo.class).createSerializer(new ExecutionConfig()), data); List<MyPojo> result = new ArrayList<MyPojo>(); source.run(new ListSourceContext<MyPojo>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testDeSerializationError() { try { TypeInformation<DeserializeTooMuchType> info = new ValueTypeInfo<DeserializeTooMuchType>(DeserializeTooMuchType.class); FromElementsFunction<DeserializeTooMuchType> source = new FromElementsFunction<DeserializeTooMuchType>( info.createSerializer(new ExecutionConfig()), new DeserializeTooMuchType()); try { source.run(new ListSourceContext<DeserializeTooMuchType>(new ArrayList<DeserializeTooMuchType>())); fail("should fail with an exception"); } catch (IOException e) { assertTrue(ExceptionUtils.stringifyException(e).contains("user-defined serialization")); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
sourceCopy.run(newCtx);