Search in sources :

Example 1 with IndexingDestination

use of org.apache.stanbol.entityhub.indexing.core.IndexingDestination in project stanbol by apache.

the class SolrYardIndexingDestinationTest method validateSolrDestination.

/**
 * Checks if the SolrYardIndexingDestination returned by the
 * {@link IndexingConfig} is valid and functional
 * @param config the configuration
 * @throws YardException indicates problems while working with the {@link SolrYard}
 * returned by {@link IndexingDestination#getYard()}
 * @throws IOException indicates problems while validating the SolrArchives
 * created by the {@link IndexingDestination#finalise()} method
 */
private void validateSolrDestination(IndexingConfig config) throws YardException, IOException {
    // get the destination
    IndexingDestination destination = config.getIndexingDestination();
    assertNotNull(destination);
    assertEquals(destination.getClass(), SolrYardIndexingDestination.class);
    // initialise
    assertTrue(destination.needsInitialisation());
    destination.initialise();
    // test that the returned Yard instance is functional
    Yard yard = destination.getYard();
    assertNotNull(yard);
    assertEquals(yard.getClass(), SolrYard.class);
    Representation rep = yard.getValueFactory().createRepresentation("http://www.example.com/entity#123");
    rep.add(NamespaceEnum.rdfs + "label", "test");
    rep.add(NamespaceEnum.rdfs + "description", "Representation to test storage while indexing");
    rep.add(RdfResourceEnum.entityRank.getUri(), Float.valueOf(0.8f));
    yard.store(rep);
    // finalise
    destination.finalise();
    // test the archives
    File expectedSolrArchiveFile = new File(config.getDistributionFolder(), config.getName() + ".solrindex.zip");
    assertTrue(expectedSolrArchiveFile.isFile());
    // validate the archive
    ZipFile archive = new ZipFile(expectedSolrArchiveFile);
    Set<String> expected = new HashSet<String>(EXPECTED_INDEX_ARCHIVE_FILE_NAMES);
    for (Enumeration<? extends ZipEntry> entries = archive.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = entries.nextElement();
        // the name of the index MUST be the root folder within the Archive!
        assertTrue(entry.getName().startsWith(config.getName()));
        String name = FilenameUtils.getName(entry.getName());
        if (expected.remove(name)) {
            log.info("found expected Entry '{}'", entry.getName());
        }
        Assert.assertFalse("found unexpected Entry '" + entry.getName() + "' in " + "SolrIndexArchive", UNEXPECTED_INDEX_ARCHIVE_FILE_NAMES.contains(name));
    }
    assertTrue("missing Files in index archive: " + expected, expected.isEmpty());
// TODO: reimplement to validate the created bundle!
// //check for the solrArchive reference file and validate required properties
// File expectedSolrArchiveReferenceFile =
// new File(,config.getName()+".solrindex.ref");
// assertTrue(expectedSolrArchiveReferenceFile.isFile());
// Properties solrRefProperties = new Properties();
// solrRefProperties.load(new FileInputStream(expectedSolrArchiveReferenceFile));
// assertTrue(solrRefProperties.getProperty("Index-Archive").equals(expectedSolrArchiveFile.getName()));
// assertTrue(solrRefProperties.getProperty("Name") != null);
}
Also used : SolrYard(org.apache.stanbol.entityhub.yard.solr.impl.SolrYard) Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) IndexingDestination(org.apache.stanbol.entityhub.indexing.core.IndexingDestination) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) ZipFile(java.util.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)1 HashSet (java.util.HashSet)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 IndexingDestination (org.apache.stanbol.entityhub.indexing.core.IndexingDestination)1 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)1 Yard (org.apache.stanbol.entityhub.servicesapi.yard.Yard)1 SolrYard (org.apache.stanbol.entityhub.yard.solr.impl.SolrYard)1