use of org.openstreetmap.osmosis.xml.v0_6.XmlReader in project osmosis by openstreetmap.
the class ChangeDeriverTest method rightEmpty.
/**
* Deriving change with an empty right input should yield
* a change with creates only.
*
* @throws Exception if something goes wrong.
*/
@Test
public void rightEmpty() throws Exception {
// Cannot be tested with file comparison as the derived
// change contains deletes which have a current timestamp
// that cannot be reliably predicted.
// Therefore, check all relevant attributes manually.
ChangeDeriver deriver = new ChangeDeriver(1);
RunnableSource left = new XmlReader(dataUtils.createDataFile("v0_6/derive_change/simple.osm"), true, CompressionMethod.None);
RunnableSource right = new EmptyReader();
SinkChangeInspector result = RunTaskUtilities.run(deriver, left, right);
List<ChangeContainer> changes = result.getProcessedChanges();
Assert.assertEquals(3, changes.size());
for (ChangeContainer changeContainer : changes) {
Assert.assertEquals(ChangeAction.Delete, changeContainer.getAction());
}
Entity e;
e = changes.get(0).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Node, e.getType());
Assert.assertEquals(10, e.getId());
Assert.assertEquals(34, e.getVersion());
e = changes.get(1).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Way, e.getType());
Assert.assertEquals(100, e.getId());
Assert.assertEquals(56, e.getVersion());
e = changes.get(2).getEntityContainer().getEntity();
Assert.assertEquals(EntityType.Relation, e.getType());
Assert.assertEquals(1000, e.getId());
Assert.assertEquals(78, e.getVersion());
}
use of org.openstreetmap.osmosis.xml.v0_6.XmlReader in project osmosis by openstreetmap.
the class EntityMergerTest method mergeAndLookForException.
/**
* Runs a merge and records the exceptions that happened during the merge.
*
* The test is considered passed iff at least one exception was thrown and
* the exception message begins with a given string.
*
* This method does not use command line parsing because it is impossible
* to check whether the right exception has been thrown. Also, as all
* exceptions are OsmosisRuntimeExceptions, we need to check the message
* so the JUnit expected exception facility is no good here.
*
* To add insult to injury, running a merge task involves three worker threads;
* the exception we expect is thrown on one of those worker threads which brings
* the pipeline down. But we want to check for that one source exception
* is thrown for the correct reason, otherwise the test becomes very unspecific.
*/
private void mergeAndLookForException(File sourceFile, String exceptionMessagePrefix) throws Exception {
final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
XmlReader reader = new XmlReader(sourceFile, false, CompressionMethod.None);
EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
RunTaskUtilities.run(merger, reader, new EmptyReader(), new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
exceptions.add(e);
}
});
// At least one of those exceptions should be a "Pipeline not sorted" one
boolean sortExceptionFound = false;
for (Throwable t : exceptions) {
if (!(t instanceof OsmosisRuntimeException)) {
Assert.fail("Unexpected exception thrown: " + t);
}
sortExceptionFound |= t.getMessage().startsWith(exceptionMessagePrefix);
}
if (!sortExceptionFound) {
Assert.fail("Expected exception not thrown");
}
}
use of org.openstreetmap.osmosis.xml.v0_6.XmlReader in project geowave by locationtech.
the class OsmXmlLoader method readOsmXml.
// Instantiation
public static OsmXmlLoader readOsmXml(final File osmxml) {
// Defines the interface for tasks consuming OSM data types.
final OsmXmlLoader sink = new OsmXmlLoader();
// compression (if any)
CompressionMethod compression = CompressionMethod.None;
if (osmxml.getName().endsWith(".gz")) {
compression = CompressionMethod.GZip;
} else if (osmxml.getName().endsWith(".bz2")) {
compression = CompressionMethod.BZip2;
}
// read source file (into sink)
final XmlReader reader = new XmlReader(osmxml, false, compression);
reader.setSink(sink);
// just run, no threading
reader.run();
return sink;
}
use of org.openstreetmap.osmosis.xml.v0_6.XmlReader in project osmosis by openstreetmap.
the class BaseReplicationDownloader method processReplicationFile.
private void processReplicationFile(File replicationFile, ReplicationState replicationState) {
try {
XmlChangeReader xmlReader;
// Send the contents of the replication file to the sink but suppress the complete
// and release methods.
xmlReader = new XmlChangeReader(replicationFile, true, CompressionMethod.GZip);
// Delegate to the sub-class to process the xml.
processChangeset(xmlReader, replicationState);
} finally {
if (!replicationFile.delete()) {
LOG.warning("Unable to delete file " + replicationFile.getName());
}
}
}
Aggregations