use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader 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.core.misc.v0_6.EmptyReader 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.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.
the class MergeBoundTest method testOneSourceEmpty.
/**
* Tests the proper working of the merge task if exactly one source is
* empty with respect to the declared bound.
*
* @throws Exception if something goes wrong
*/
@Test
public void testOneSourceEmpty() throws Exception {
RunnableSource source0 = new EmptyReader();
Bound bound1 = new Bound(5, 6, 8, 7, "source2");
RunnableSource source1 = new BoundSource(bound1, true);
EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
List<EntityContainer> mergedList = createList(merged.getProcessedEntities());
Assert.assertEquals(2, mergedList.size());
Assert.assertEquals(bound1, mergedList.get(0).getEntity());
Assert.assertEquals(EntityType.Node, mergedList.get(1).getEntity().getType());
}
use of org.openstreetmap.osmosis.core.misc.v0_6.EmptyReader in project osmosis by openstreetmap.
the class MergeBoundTest method testBothEmpty.
/**
* Tests the proper working of the merge task if both sources are
* empty.
*
* @throws Exception if something goes wrong
*/
@Test
public void testBothEmpty() throws Exception {
RunnableSource source0 = new EmptyReader();
RunnableSource source1 = new EmptyReader();
EntityMerger merger = new EntityMerger(ConflictResolutionMethod.LatestSource, 1, BoundRemovedAction.Ignore);
SinkEntityInspector merged = RunTaskUtilities.run(merger, source0, source1);
Assert.assertTrue("Expected empty result set but got some data", merged.getLastEntityContainer() == null);
}
Aggregations