Changeset 2826


Ignore:
Timestamp:
04/22/13 13:32:04 (11 years ago)
Author:
keeloo
Message:

Repaired the importer test: made it transparent regarding the
deleteAllFirst parameter.

Added the parameter and logic that causes large files to be
filtered. Added accompanying tests in the vlo test configuration
package.

Location:
vlo/trunk/vlo_importer/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java

    r2810 r2826  
    162162   
    163163    @Element
    164     private static int maxOnHeap = 1000;
     164    private static int maxOnHeap = 0;
     165   
     166    @Element
     167    private static boolean useMaxFileSize = false;
     168   
     169    @Element
     170    private static int maxFileSize = 0;
    165171   
    166172    @Element
     
    278284   
    279285    /**
     286     * Get the value of the useMaxFileSize parameter<br><br>
     287     *
     288     * For a description of the parameter, refer to the general VLO
     289     * documentation.
     290     *
     291     * @return the value
     292     */
     293    public static boolean getUseMaxFileSize (){
     294        return useMaxFileSize;
     295    }
     296   
     297    /**
     298     * Set the value of the useMaxFileSize parameter<br><br>
     299     *
     300     * For a description of the parameter, refer to the general VLO
     301     * documentation.
     302     *
     303     * @param param the value
     304     */
     305    public static void setUseMaxFileSize (boolean param){
     306        useMaxFileSize = param;
     307    }
     308   
     309    /**
     310     * Get the value of the maxFileSize parameter<br><br>
     311     *
     312     * For a description of the parameter, refer to the general VLO
     313     * documentation.
     314     *
     315     * @return the value
     316     */
     317    public static int getMaxFileSize (){
     318        return maxFileSize;
     319    }
     320   
     321    /**
     322     * Set the value of the maxFileSize parameter<br><br>
     323     *
     324     * For a description of the parameter, refer to the general VLO
     325     * documentation.
     326     *
     327     * @param param the value
     328     */
     329    public static void setMaxFileSize (int param){
     330        maxFileSize = param;
     331    }
     332   
     333    /**
    280334     * Get the value of the useHandleResolver parameter<br><br>
    281335     *
  • vlo/trunk/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r2810 r2826  
    5151     * Log log log log
    5252     */
    53     private final static Logger LOG = LoggerFactory.getLogger(MetadataImporter.class);
     53    protected final static Logger LOG = LoggerFactory.getLogger(MetadataImporter.class);
    5454    /**
    5555     * Some place to store errors.
     
    8888     * Just to know what we have already done.
    8989     */
    90     private final Set<String> processedIds = new HashSet<String>();
     90    protected final Set<String> processedIds = new HashSet<String>();
    9191    /**
    9292     * Some caching for solr documents (we are more efficient if we ram a whole
     
    9696
    9797    // SOME STATS
    98     private int nrOFDocumentsUpdated;
    99     private int nrOfFilesAnalyzed = 0;
    100     private int nrOfFilesWithoutId = 0;
    101     private int nrOfFilesWithoutDataResources = 0;
    102     private int nrOfFilesWithError = 0;
     98    protected int nrOFDocumentsUpdated;
     99    protected int nrOfFilesAnalyzed = 0;
     100    protected int nrOfFilesWithoutId = 0;
     101    protected int nrOfFilesWithoutDataResources = 0;
     102    protected int nrOfFilesWithError = 0;
    103103
    104104    /**
     
    131131                List<File> files = getFilesFromDataRoot(dataRoot.getRootFile());
    132132                for (File file : files) {
    133                     LOG.debug("PROCESSING FILE: " + file.getAbsolutePath());
    134                     processCmdi(file, dataRoot, processor);
     133                    if (VloConfig.getUseMaxFileSize() &&
     134                            file.length() > VloConfig.getMaxFileSize()) {
     135                        LOG.info("Skipping " + file.getAbsolutePath() + " because it is too large.");
     136                    } else {
     137                        LOG.debug("PROCESSING FILE: " + file.getAbsolutePath());
     138                        processCmdi(file, dataRoot, processor);
     139                    }
    135140                }
    136141                if (!docs.isEmpty()) {
     
    170175     * @return
    171176     */
    172     private List<DataRoot> checkDataRoots() {
     177    protected List<DataRoot> checkDataRoots() {
    173178        List<DataRoot> dataRoots = VloConfig.getDataRoots();
    174179        for (DataRoot dataRoot : dataRoots) {
     
    189194     * directory
    190195     */
    191     private List<File> getFilesFromDataRoot(File rootFile) {
     196    protected List<File> getFilesFromDataRoot(File rootFile) {
    192197        List<File> result = new ArrayList<File>();
    193198        if (rootFile.isFile()) {
     
    226231     * @throws IOException
    227232     */
    228     private void processCmdi(File file, DataRoot dataOrigin, CMDIDataProcessor processor) throws SolrServerException, IOException {
     233    protected void processCmdi(File file, DataRoot dataOrigin, CMDIDataProcessor processor) throws SolrServerException, IOException {
    229234        nrOfFilesAnalyzed++;
    230235        CMDIData cmdiData = null;
     
    262267     * @return true if id is acceptable, false otherwise
    263268     */
    264     private boolean idOk(String id) {
     269    protected boolean idOk(String id) {
    265270        return id != null && !id.isEmpty();
    266271    }
     
    278283     * @throws IOException
    279284     */
    280     private void updateDocument(SolrInputDocument solrDocument, CMDIData cmdiData, File file, DataRoot dataOrigin) throws SolrServerException,
     285    protected void updateDocument(SolrInputDocument solrDocument, CMDIData cmdiData, File file, DataRoot dataOrigin) throws SolrServerException,
    281286            IOException {
    282287        if (!solrDocument.containsKey(FacetConstants.FIELD_COLLECTION)) {
     
    318323     * a type is overwritten and already in the solrDocument we take that type.
    319324     */
    320     private void addResourceData(SolrInputDocument solrDocument, CMDIData cmdiData) {
     325    protected void addResourceData(SolrInputDocument solrDocument, CMDIData cmdiData) {
    321326        List<Object> fieldValues = solrDocument.containsKey(FacetConstants.FIELD_RESOURCE_TYPE) ? new ArrayList<Object>(solrDocument
    322327                .getFieldValues(FacetConstants.FIELD_RESOURCE_TYPE)) : null;
  • vlo/trunk/vlo_importer/src/main/resources/VloConfig.xml

    r2814 r2826  
    44   
    55    <maxOnHeap>128</maxOnHeap>
     6   
     7    <useMaxFileSize>false</useMaxFileSize>
     8   
     9    <maxFileSize>20000000</maxFileSize>
    610   
    711    <useHandleResolver>false</useHandleResolver>
  • vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/config/VloConfigTest.java

    r2816 r2826  
    8888
    8989    /**
    90      * Test the getVloHomeLink method
     90     * Test the getMaxOnHeap method
    9191     */
    9292    @Test
     
    102102
    103103    /**
    104      * Test the setVloHomeLink method
     104     * Test the setMaxOnHeap method
    105105     */
    106106    @Test
     
    119119   
    120120    /**
     121     * Test the getUseMaxFileSize method
     122     */
     123    @Test
     124    public void testGetUseMaxFileSize() {
     125       
     126        System.out.println("getUseMaxFileSize");
     127       
     128        boolean expResult = false;
     129        boolean result = VloConfig.getUseMaxFileSize();
     130       
     131        assertEquals(expResult, result);
     132    }
     133
     134    /**
     135     * Test the setSetUseMaxFileSize method
     136     */
     137    @Test
     138    public void testSetUseMaxFileSize() {
     139       
     140        System.out.println("setUseMaxFileSize");
     141       
     142        boolean param = true;
     143       
     144        VloConfig.setUseMaxFileSize(param);
     145
     146        boolean result = VloConfig.getUseMaxFileSize();
     147       
     148        assertEquals(param, result);
     149    }
     150   
     151        /**
     152     * Test the getMaxFileSize method
     153     */
     154    @Test
     155    public void testGetMaxFileSize() {
     156       
     157        System.out.println("getMaxFileSize");
     158       
     159        int expResult = 20000000;
     160        int result = VloConfig.getMaxFileSize();
     161       
     162        assertEquals(expResult, result);
     163    }
     164
     165    /**
     166     * Test the setMaxFileSize method
     167     */
     168    @Test
     169    public void testSetMaxFileSize() {
     170       
     171        System.out.println("setMaxFileSize");
     172       
     173        int param = 10000000;
     174       
     175        VloConfig.setMaxFileSize(param);
     176
     177        int result = VloConfig.getMaxFileSize();
     178       
     179        assertEquals(param, result);
     180    }
     181   
     182    /**
    121183     * Test the getHandleResolver method
    122184     */
     
    124186    public void testGetUseHandleResolver() {
    125187       
    126         System.out.println("getMaxOnHeap");
     188        System.out.println("getUseHandleResolver");
    127189       
    128190        boolean expResult = false;
     
    138200    public void testSetUseHandleResolver() {
    139201       
    140         System.out.println("setMaxOnHeap");
     202        System.out.println("setUseHandleResolver");
    141203       
    142204        boolean param = true;
  • vlo/trunk/vlo_importer/src/test/java/eu/clarin/cmdi/vlo/importer/MetadataImporterTest.java

    r2816 r2826  
    1111import java.util.Collections;
    1212import java.util.List;
     13import java.util.logging.Level;
     14import java.util.logging.Logger;
    1315import org.apache.solr.client.solrj.SolrServerException;
    1416import org.apache.solr.common.SolrInputDocument;
     
    236238        final List<SolrInputDocument> result = new ArrayList<SolrInputDocument>();
    237239               
    238         // read configuration in ImporterTestCase.setup; change it now
     240        /*
     241         * Read configuration in ImporterTestCase.setup and change the setup to
     242         * suit the test.
     243         */
    239244       
    240245        modifyConfig(rootFile);
     
    242247        MetadataImporter importer;
    243248        importer = new MetadataImporter() {
     249            /*
     250             * Because in the test, the solr server is not assumed to be
     251             * available, override the importer's class startImport method by
     252             * leaving out interaction with server.
     253             *
     254             * By invoking the processCmdi method, the class being defined here
     255             * needs to anticipate on an exception possibly thrown by the
     256             * processCmdi method invoking the sendDocs method. Please note
     257             * however, that the latter method is overriden, and the actual
     258             * database is being replaced by an array of documents.
     259             */
    244260            @Override
    245             protected void initSolrServer() throws MalformedURLException {
    246                 //do nothing no solrserver in test
     261            void startImport() throws MalformedURLException {
     262
     263                List<DataRoot> dataRoots = checkDataRoots();
     264                long start = System.currentTimeMillis();
     265                try {
     266
     267                    for (DataRoot dataRoot : dataRoots) {
     268                        LOG.info("Start of processing: " +
     269                                dataRoot.getOriginName());
     270                        CMDIDataProcessor processor = new
     271                                CMDIParserVTDXML(POST_PROCESSORS);
     272                        List<File> files =
     273                                getFilesFromDataRoot(dataRoot.getRootFile());
     274                        for (File file : files) {
     275                            if (VloConfig.getUseMaxFileSize()
     276                                    && file.length() >
     277                                    VloConfig.getMaxFileSize()) {
     278                                LOG.info("Skipping " + file.getAbsolutePath() +
     279                                        " because it is too large.");
     280                            } else {
     281                                LOG.debug("PROCESSING FILE: " +
     282                                        file.getAbsolutePath());               
     283                                /*
     284                                 * Anticipate on the solr exception that will
     285                                 * never by raised because sendDocs is overriden
     286                                 * in a suitable way.
     287                                 */
     288                                try {
     289                                    processCmdi(file, dataRoot, processor);
     290                                } catch (SolrServerException ex) {
     291                                    Logger.getLogger(MetadataImporterTest.class.getName()).log(Level.SEVERE, null, ex);
     292                                }
     293                            }
     294                        }
     295                        if (!docs.isEmpty()) {
     296                            sendDocs();
     297                        }
     298                        LOG.info("End of processing: " +
     299                                dataRoot.getOriginName());
     300                    }
     301                   
     302                } catch (IOException e) {
     303                    LOG.error("error updating files:\n", e);
     304                } finally {
     305
     306                }
     307                long took = (System.currentTimeMillis() - start) / 1000;
     308                LOG.info("Found " + nrOfFilesWithoutId +
     309                        " file(s) without an id. (id is generated based on fileName but that may not be unique)");
     310                LOG.info("Found " + nrOfFilesWithError +
     311                        " file(s) with errors.");
     312                LOG.info("Found " + nrOfFilesWithoutDataResources
     313                        + " file(s) without data resources (metadata descriptions without resources are ignored).");
     314                LOG.info("Update of " + nrOFDocumentsUpdated + " took " + took +
     315                        " secs. Total nr of files analyzed " + nrOfFilesAnalyzed);
    247316            }
    248317
     318            /*
     319             * Replace the server's database by a document array
     320             */
    249321            @Override
    250             protected void sendDocs() throws SolrServerException, IOException {
    251             //overriding here so we can test the docs
     322            protected void sendDocs() throws IOException {
     323               
    252324                result.addAll(this.docs);
    253325                docs = new ArrayList<SolrInputDocument>();
     
    266338        dataRoot.setPrefix("http://example.com");
    267339        VloConfig.setDataRoots(Collections.singletonList(dataRoot));
    268        
    269         /**
    270          * Please observe that if the deleteAllFirst parameter is true, the
    271          * startImport method in the MetaDataImporter class will refer to an
    272          * instance of the solr server. Because in this test initSolrServer
    273          * method is empty, no solr server is create. Therefore, the value of
    274          * the deleteAllFirst parameter needs to be false.
    275          */
    276         VloConfig.setDeleteAllFirst(false);
    277340    }
    278341
Note: See TracChangeset for help on using the changeset viewer.