use of org.apache.hop.core.logging.ILogChannel in project hop by apache.
the class ExtensionPointIntegrationTest method testExtensionPointMapConcurrency.
@Test
public void testExtensionPointMapConcurrency() throws InterruptedException {
final ILogChannel log = mock(ILogChannel.class);
List<Runnable> parallelTasksList = new ArrayList<>(TOTAL_THREADS_TO_RUN);
for (int i = 0; i < TOTAL_THREADS_TO_RUN; i++) {
parallelTasksList.add(() -> {
HopExtensionPoint hopExtensionPoint = getRandomHopExtensionPoint();
IPlugin pluginInterface = PluginRegistry.getInstance().getPlugin(ExtensionPointPluginType.class, "id" + hopExtensionPoint.id);
try {
PluginRegistry.getInstance().removePlugin(ExtensionPointPluginType.class, pluginInterface);
PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
} catch (HopPluginException e) {
e.printStackTrace();
} catch (NullPointerException e) {
// NullPointerException can be thrown if trying to remove a plugin that doesn't exit,
// discarding occurence
}
ExtensionPointMap.getInstance().reInitialize();
try {
ExtensionPointMap.getInstance().callExtensionPoint(log, null, hopExtensionPoint.id, null);
} catch (HopException e) {
e.printStackTrace();
}
});
}
assertConcurrent(parallelTasksList);
}
use of org.apache.hop.core.logging.ILogChannel in project hop by apache.
the class DrawDiffOnActionExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
if (!(object instanceof WorkflowPainter)) {
return;
}
WorkflowPainter painter = (WorkflowPainter) object;
Point offset = painter.getOffset();
IGc gc = painter.getGc();
WorkflowMeta workflowMeta = painter.getWorkflowMeta();
try {
workflowMeta.getActions().stream().filter(je -> je.getAttribute(ATTR_GIT, ATTR_STATUS) != null).forEach(je -> {
if (workflowMeta.getWorkflowVersion() == null ? false : workflowMeta.getWorkflowVersion().startsWith("git")) {
String status = je.getAttribute(ATTR_GIT, ATTR_STATUS);
Point n = je.getLocation();
String location;
if (status.equals(REMOVED)) {
location = "removed.svg";
} else if (status.equals(CHANGED)) {
location = "changed.svg";
} else if (status.equals(ADDED)) {
location = "added.svg";
} else {
// Unchanged
return;
}
int iconSize = ConstUi.ICON_SIZE;
try {
iconSize = PropsUi.getInstance().getIconSize();
} catch (Exception e) {
// Exception when accessed from Hop Server
}
int x = (n.x + iconSize + offset.x) - (iconSize / 4);
int y = n.y + offset.y - (iconSize / 4);
try {
gc.drawImage(new SvgFile(location, getClass().getClassLoader()), x, y, iconSize / 4, iconSize / 4, gc.getMagnification(), 0);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
je.getAttributesMap().remove(ATTR_GIT);
}
});
} catch (Exception e) {
throw new HopException("Error drawing status icon on action", e);
}
}
use of org.apache.hop.core.logging.ILogChannel in project hop by apache.
the class DrawDiffOnTransformExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
if (!(object instanceof PipelinePainter)) {
return;
}
PipelinePainter painter = (PipelinePainter) object;
Point offset = painter.getOffset();
IGc gc = painter.getGc();
PipelineMeta pipelineMeta = painter.getPipelineMeta();
try {
pipelineMeta.getTransforms().stream().filter(transform -> transform.getAttribute(ATTR_GIT, ATTR_STATUS) != null).forEach(transform -> {
if (pipelineMeta.getPipelineVersion() != null && pipelineMeta.getPipelineVersion().startsWith("git")) {
String status = transform.getAttribute(ATTR_GIT, ATTR_STATUS);
Point n = transform.getLocation();
String location;
if (status.equals(REMOVED)) {
location = "removed.svg";
} else if (status.equals(CHANGED)) {
location = "changed.svg";
} else if (status.equals(ADDED)) {
location = "added.svg";
} else {
// Unchanged
return;
}
int iconSize = ConstUi.ICON_SIZE;
try {
iconSize = PropsUi.getInstance().getIconSize();
} catch (Exception e) {
// Exception when accessed from Hop Server
}
int x = (n.x + iconSize + offset.x) - (iconSize / 4);
int y = n.y + offset.y - (iconSize / 4);
try {
gc.drawImage(new SvgFile(location, getClass().getClassLoader()), x, y, iconSize / 2, iconSize / 2, gc.getMagnification(), 0);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
transform.getAttributesMap().remove(ATTR_GIT);
}
});
} catch (Exception e) {
throw new HopException("Error drawing status on transform", e);
}
}
use of org.apache.hop.core.logging.ILogChannel in project hop by apache.
the class MongoDbOutputMetaInjectionTest method setHopLogFactoryWithMock.
public static void setHopLogFactoryWithMock() {
ILogChannelFactory logChannelInterfaceFactory = mock(ILogChannelFactory.class);
ILogChannel logChannelInterface = mock(ILogChannel.class);
when(logChannelInterfaceFactory.create(any())).thenReturn(logChannelInterface);
HopLogStore.setLogChannelFactory(logChannelInterfaceFactory);
}
use of org.apache.hop.core.logging.ILogChannel in project hop by apache.
the class MongoDbOutputDataTest method testApplyIndexesOptions.
@Test
public void testApplyIndexesOptions() throws HopException, MongoDbException {
MongoDbOutputData data = new MongoDbOutputData();
ILogChannel log = LogChannel.GENERAL;
DBCollection collection = mock(DBCollection.class);
MongoCollectionWrapper collectionWrapper = spy(new DefaultMongoCollectionWrapper(collection));
data.setCollection(collectionWrapper);
ArgumentCaptor<BasicDBObject> captorIndexes = ArgumentCaptor.forClass(BasicDBObject.class);
ArgumentCaptor<BasicDBObject> captorOptions = ArgumentCaptor.forClass(BasicDBObject.class);
doNothing().when(collectionWrapper).createIndex(captorIndexes.capture(), captorOptions.capture());
MongoIndex index = new MongoIndex();
index.pathToFields = "FirstName:1";
index.drop = false;
index.sparse = false;
index.unique = false;
// Test with all options false
data.applyIndexes(Collections.singletonList(index), log, false);
BasicDBObject createdIndex = captorIndexes.getValue();
BasicDBObject createdOptions = captorOptions.getValue();
assertEquals(1, createdIndex.size());
assertTrue(createdIndex.containsField("FirstName"));
assertEquals("1", createdIndex.getString("FirstName"));
assertTrue(createdOptions.containsField("background"));
assertTrue(createdOptions.getBoolean("background"));
assertTrue(createdOptions.containsField("sparse"));
assertFalse(createdOptions.getBoolean("sparse"));
assertTrue(createdOptions.containsField("unique"));
assertFalse(createdOptions.getBoolean("unique"));
// Test with only "sparse" true
index.sparse = true;
index.unique = false;
data.applyIndexes(Collections.singletonList(index), log, false);
createdIndex = captorIndexes.getValue();
createdOptions = captorOptions.getValue();
assertEquals(1, createdIndex.size());
assertTrue(createdIndex.containsField("FirstName"));
assertEquals("1", createdIndex.getString("FirstName"));
assertTrue(createdOptions.containsField("background"));
assertTrue(createdOptions.getBoolean("background"));
assertTrue(createdOptions.containsField("sparse"));
assertTrue(createdOptions.getBoolean("sparse"));
assertTrue(createdOptions.containsField("unique"));
assertFalse(createdOptions.getBoolean("unique"));
// Test with only "unique" true
index.sparse = false;
index.unique = true;
data.applyIndexes(Collections.singletonList(index), log, false);
createdIndex = captorIndexes.getValue();
createdOptions = captorOptions.getValue();
assertEquals(1, createdIndex.size());
assertTrue(createdIndex.containsField("FirstName"));
assertEquals("1", createdIndex.getString("FirstName"));
assertTrue(createdOptions.containsField("background"));
assertTrue(createdOptions.getBoolean("background"));
assertTrue(createdOptions.containsField("sparse"));
assertFalse(createdOptions.getBoolean("sparse"));
assertTrue(createdOptions.containsField("unique"));
assertTrue(createdOptions.getBoolean("unique"));
// Test with "sparse" and "unique" true
index.sparse = true;
index.unique = true;
data.applyIndexes(Collections.singletonList(index), log, false);
createdIndex = captorIndexes.getValue();
createdOptions = captorOptions.getValue();
assertEquals(1, createdIndex.size());
assertTrue(createdIndex.containsField("FirstName"));
assertEquals("1", createdIndex.getString("FirstName"));
assertTrue(createdOptions.containsField("background"));
assertTrue(createdOptions.getBoolean("background"));
assertTrue(createdOptions.containsField("sparse"));
assertTrue(createdOptions.getBoolean("sparse"));
assertTrue(createdOptions.containsField("unique"));
assertTrue(createdOptions.getBoolean("unique"));
}
Aggregations