Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue31: proposed fix #32

Open
wants to merge 5 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
target/
.idea/
ic-amqp-plugin.iml
26 changes: 13 additions & 13 deletions src/main/java/com/instaclick/pentaho/plugin/amqp/AMQPPlugin.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.instaclick.pentaho.plugin.amqp;

import java.io.IOException;
import com.instaclick.pentaho.plugin.amqp.processor.Processor;
import com.instaclick.pentaho.plugin.amqp.processor.ProcessorFactory;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.row.RowMeta;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransListener;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.di.trans.step.*;

import java.io.IOException;

import static com.instaclick.pentaho.plugin.amqp.Messages.getString;
import com.instaclick.pentaho.plugin.amqp.processor.Processor;
import com.instaclick.pentaho.plugin.amqp.processor.ProcessorFactory;
import static org.pentaho.di.core.encryption.KettleTwoWayPasswordEncoder.decryptPasswordOptionallyEncrypted;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.row.RowMeta;
import org.pentaho.di.trans.TransListener;
import org.pentaho.di.core.row.RowMetaInterface;

public class AMQPPlugin extends BaseStep implements StepInterface
{
Expand Down Expand Up @@ -171,7 +169,9 @@ private void initPluginStep() throws Exception

data.uri = uri;
data.host = host;
data.port = port;
if (port != null) {
data.port = port;
}
data.vhost = vhost;
data.username = username;
data.password = password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.instaclick.pentaho.plugin.amqp.processor;

import com.instaclick.pentaho.plugin.amqp.initializer.Initializer;
import com.instaclick.pentaho.plugin.amqp.AMQPPlugin;
import com.instaclick.pentaho.plugin.amqp.AMQPPluginData;
import com.instaclick.pentaho.plugin.amqp.initializer.Initializer;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.pentaho.di.core.exception.KettleStepException;

import java.io.IOException;
import java.util.List;
import org.pentaho.di.core.exception.KettleStepException;

abstract class BaseProcessor implements Processor
{
Expand Down Expand Up @@ -81,6 +83,13 @@ public void shutdown() throws IOException
if (channel.isOpen()) {
channel.close();
}

if (channel != null) {
Connection connection = channel.getConnection();
if (connection.isOpen()) {
connection.close();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@

package com.instaclick.pentaho.plugin.amqp.processor;

import com.instaclick.pentaho.plugin.amqp.initializer.Initializer;
import com.instaclick.pentaho.plugin.amqp.AMQPPlugin;
import com.instaclick.pentaho.plugin.amqp.AMQPPluginData;
import com.instaclick.pentaho.plugin.amqp.initializer.Initializer;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.row.RowMetaInterface;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.*;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.row.RowMetaInterface;

public class AbstractProcessorTest
{
AMQPPluginData data;
AMQPPlugin plugin;
Channel channel;
Connection connection;

@Before
public void setUp()
{
channel = mock(Channel.class, RETURNS_MOCKS);
connection = mock(Connection.class, RETURNS_MOCKS);
data = mock(AMQPPluginData.class);
plugin = mock(AMQPPlugin.class);
}
Expand Down Expand Up @@ -120,8 +126,11 @@ public void testShutdownClosesChannel() throws IOException
final BaseProcessor processor = new AbstractProcessorImpl(channel, plugin, data);

when(channel.isOpen()).thenReturn(true);
when(channel.getConnection()).thenReturn(connection);
when(connection.isOpen()).thenReturn(true);
processor.shutdown();
verify(channel, times(1)).close();
verify(channel, times(1)).getConnection();
verify(connection, times(1)).close();
}

@Test
Expand Down