Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Add a workflow task that sends a message to topic in TIBCO #123

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

ydayagi
Copy link
Contributor

@ydayagi ydayagi commented Mar 17, 2023

@ydayagi ydayagi force-pushed the flpath145 branch 2 times, most recently from 2b29fe1 to 7a96bf6 Compare March 20, 2023 08:16
Comment on lines 23 to 27
private Tibjms service;
private String url;
private String caFile;
private String username;
private String password;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make these private final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gciavarrini fixed

Comment on lines 23 to 28
String caFile = "/cafile";
String url = "ssl://localhost:7222";
String username = "username";
String passowrd = "password";
String topic = "topic";
String message = "test message";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make this private final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private = it's a best practice to keep the scope as narrow as you can.
final = It's a good practice to declare final a variable to be sure that it won't be modified unintentionally, and in addition it makes the understanding of code easier.

TBH this strings can be declared private static final so we're stating that such variables are constants and that they are associated with the class (not the instance of the class)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gciavarrini fixed

Comment on lines 29 to 30
Tibjms tibjms = Mockito.mock(Tibjms.class);
TibcoWorkFlowTask task = new TibcoWorkFlowTask(tibjms, url, caFile, username, passowrd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good practice to initialize objects in @Before method.
In this way, the object is recreated before each test.

In addition, make these objects private as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good practice? I don't think so. Not in this case. In the case of simple initialization, we have the Java language that works for us. You don't need to use additional libraries.
Why make them private? No one is going to use this class outside the test. The default is package-private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you modify the object inside one of tests, then following tests will use a "dirty" object.
Regarding the private = It's a good practice to start to use the narrow privilege and the increase it if needed (so, private is more restrictive then package-private). Ideally, a good practice is to create immutable classes, but I understand that we can be flexible in this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Before does not solve it. It only happens once in the beginning. If test A changes something then test B will see a dirty obj.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're confusing @Before with @BeforeClass

public class Example {

	@BeforeClass
	public static void classSetUp(){
		System.out.println("Before Class");
	}
	@Before
	public void setUp(){
		System.out.println("Before");
	}

	@Test
	public void test1(){
		System.out.println("Test 1");
	}

	@Test
	public void test2(){
		System.out.println("Test 2");
	}
}

when you execute all the tests in the Example class then they print:

Before Class
Before
Test 1
Before
Test 2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,34 @@
// @formatter:off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary to disable the formatter for the whole file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I don't need to execute it for every change. I don't need this formatter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will eventually end as s project with multiple formatting while the convention is to use spring formatted.
while I find it PITA to keep running the formatted, we'd better handle auto-format rather than skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not skip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gciavarrini fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still there. Can you double check?

pom.xml Outdated
@@ -62,6 +62,7 @@
<module>notification-service</module>
<module>pattern-detection-library</module>
<module>coverage</module>
<module>tasks</module>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is going to be used for all common tasks
I think it should be renamed to more informative name
I suggest: workflow-common-tasks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know it is common. We know it is for workflow. Why add all this text? I can somehow understand the addition of 'workflow-'. Some how ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know its common, I'm not sure how clear it would be for new users, I think its better to make it explicit so it would more clear.
Anyway, I don't have any problem with changing to workflow-tasks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used prebuilt-tasks. workflow-tasks collides with existing workflow task objects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirarg fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to keep this module directory only with the tasks files
Remove all other utils files to another sub-directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only makes it more complex. I will move the whole tibco task to a sub-directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, for the long term, we would like to avoid having one directory contains many files
Need to keep it clean, maybe should use here more hierarchical folders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more hierarchy more problems more difficulties reading and following files

@ydayagi
Copy link
Contributor Author

ydayagi commented Mar 20, 2023

/retest

@ydayagi ydayagi force-pushed the flpath145 branch 3 times, most recently from b8e2d18 to 1b60873 Compare March 20, 2023 12:14
@@ -0,0 +1,10 @@
#!/bin/bash
if [ -f "tibjms.jar" ]; then exit 0; fi
rm -rf /tmp/tibco
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe mktemp -d tibco-XXX ?
(just in case there are few build processes running on the same machine)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really? isn't each build in its own container?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. maybe @eloycoto knows?

pom.xml Show resolved Hide resolved
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen a direct use of this dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not add it. I think it is for the '@slf4j'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'@slf4j' comes from lombok. pls try to build without that dependency and see if it is actually being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

workflow-examples/README.md Outdated Show resolved Hide resolved
<groupId>dev.parodos</groupId>
<artifactId>prebuilt-tasks</artifactId>
<version>${revision}</version>
<scope>compile</scope>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile is the default scope. It can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@masayag fixed

@@ -0,0 +1,34 @@
// @formatter:off
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will eventually end as s project with multiple formatting while the convention is to use spring formatted.
while I find it PITA to keep running the formatted, we'd better handle auto-format rather than skip it.

String topic = getParameterValue(workContext, "topic");
String message = getParameterValue(workContext, "message");

log.debug("sending to topic " + topic + " message: " + message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of string concatenation, use

log.debug("sending to topic {} message: {}", topic, message);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and that's why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what preventing approval of this PR?

Comment on lines 67 to 74
map = Map.of("topic",topic,"message",message);
} else {
map = new HashMap();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do not create the HashMap before the if and then add value if withParams is true ?

HashMap<String, String> map = new HashMap<>();
if(withParams){
    map.put("topic", topic);
    map.put("message", message);
}

In addition, map is a variable name too generic, what about messageMap or something more "declarative"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? see my previous comment. I changed it just so we can continue

@@ -0,0 +1,34 @@
// @formatter:off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still there. Can you double check?

Comment on lines 25 to 32
private final String caFile = "/cafile";
private final String url = "ssl://localhost:7222";
private final String username = "username";
private final String passowrd = "password";
private final String topic = "topic";
private final String message = "test message";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing static as per our previous discussion :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it really matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@ydayagi ydayagi force-pushed the flpath145 branch 5 times, most recently from 709c466 to a527101 Compare March 22, 2023 10:33
@masayag
Copy link
Collaborator

masayag commented Mar 22, 2023

lgtm

@gciavarrini
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Mar 22, 2023
@pkliczewski
Copy link
Collaborator

pkliczewski commented Mar 23, 2023

@gciavarrini please remove requested changes

@pkliczewski
Copy link
Collaborator

/approve

Copy link
Contributor

@gciavarrini gciavarrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Mar 23, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gciavarrini, pkliczewski, ydayagi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 258fd2d into parodos-dev:main Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants