/** * Is entity class cells. * * @param extractorConfig the extractor config * @return the boolean */ private boolean isEntityClassCells(ExtractorConfig extractorConfig) { if (extractorConfig.getEntityClass().isAssignableFrom(Cells.class)) { return true; } return false; }
/** * @param config */ @SuppressWarnings("unchecked") private void initExtractor(ExtractorConfig<T> config) { try { Class<T> rdd = config.getExtractorImplClass(); if (rdd == null) { rdd = (Class<T>) Class.forName(config.getExtractorImplClassName()); } Constructor<T> c = null; if (config.getEntityClass().isAssignableFrom(Cells.class)) { c = rdd.getConstructor(); this.extractor = (IExtractor<T, ExtractorConfig<T>>) c.newInstance(); } else { c = rdd.getConstructor(Class.class); this.extractor = (IExtractor<T, ExtractorConfig<T>>) c.newInstance(config.getEntityClass()); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOG.error("Impossible to make an extractor instance, check classpath " + e.getMessage()); throw new DeepInstantiationException( "Impossible to make an extractor instance, check classpath " + e.getMessage()); } }
/** * @param config */ @SuppressWarnings("unchecked") private void initExtractor(ExtractorConfig<T> config) { try { Class<T> rdd = config.getExtractorImplClass(); if (rdd == null) { rdd = (Class<T>) Class.forName(config.getExtractorImplClassName()); } Constructor<T> c = null; if (config.getEntityClass().isAssignableFrom(Cells.class)) { c = rdd.getConstructor(); this.extractor = (IExtractor<T, ExtractorConfig<T>>) c.newInstance(); } else { c = rdd.getConstructor(Class.class); this.extractor = (IExtractor<T, ExtractorConfig<T>>) c.newInstance(config.getEntityClass()); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOG.error("Impossible to make an extractor instance, check classpath " + e.getMessage()); throw new DeepInstantiationException( "Impossible to make an extractor instance, check classpath " + e.getMessage()); } }
setEntityClass(extractorConfig.getEntityClass()); setRddId(extractorConfig.getRddId()); setPartitionId(extractorConfig.getPartitionId());
setEntityClass(extractorConfig.getEntityClass()); setRddId(extractorConfig.getRddId()); setPartitionId(extractorConfig.getPartitionId());
if (inputConfigEntity.getEntityClass().isAssignableFrom(Cells.class)) { outputConfigEntity = (ExtractorConfig<W>) getWriteExtractorConfig("outputCells", Cells.class); } else { if (inputConfigEntity.getEntityClass().isAssignableFrom(Cells.class)) { Assert.assertEquals(((Cells) outputRDDEntity.first()).getCellByName("message").getCellValue(), READ_FIELD_EXPECTED);
/** * It tests if the extractor can read from the data store * * @param <W> the type parameter */ @Test(alwaysRun = true, groups = { "FunctionalTests" }) public <W> void testRead() { DeepSparkContext context = getDeepSparkContext(); try { ExtractorConfig<W> inputConfigEntity = getReadExtractorConfig(databaseExtractorName, tableRead, inputEntity); RDD<W> inputRDDEntity = context.createRDD(inputConfigEntity); Assert.assertEquals(READ_COUNT_EXPECTED, inputRDDEntity.count()); if (inputConfigEntity.getEntityClass().isAssignableFrom(Cells.class)) { Assert.assertEquals(((Cells) inputRDDEntity.first()).getCellByName("message").getCellValue(), READ_FIELD_EXPECTED); Assert.assertEquals(((Cells) inputRDDEntity.first()).getCellByName("id").getCellValue(), ID_MESSAGE_EXPECTED); } else { Assert.assertEquals(((MessageTestEntity) inputRDDEntity.first()).getMessage(), READ_FIELD_EXPECTED); Assert.assertEquals(((MessageTestEntity) inputRDDEntity.first()).getId(), ID_MESSAGE_EXPECTED); } } finally { context.stop(); } }