Skip to content

Conversation

@angelahuqing
Copy link
Collaborator

Addition of a jobs queue class and testing implemented through the shared async map

@angelahuqing angelahuqing requested a review from a team as a code owner March 2, 2023 00:40
@angelahuqing angelahuqing marked this pull request as draft March 9, 2023 06:08
# This is the 1st commit message:

SERV-505 Added jobsQueue to watcherVerticle

# This is the commit message #2:

[SERV-505] Addition of JobsQueue Class and Test

# This is the commit message #3:

[SERV-505] Consistency update to CsvItemTest.java

# This is the commit message #4:

[SERV-505] Cleaned up JobsQueue code

# This is the commit message #5:

[SERV-505] Completion of JobsQueue functionality and added to WatcherVerticle

# This is the commit message #6:

[SERV-505] Added in messages

# This is the commit message #7:

[SERV-505] Fix checkstyle and delete unnecessary files

# This is the commit message #8:

[SERV-505] Fixed checkstyle violations
@angelahuqing angelahuqing marked this pull request as ready for review March 17, 2023 17:53
Copy link

@markmatney markmatney left a comment

Choose a reason for hiding this comment

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

In addition, please remove all of the .DS_Store files and add an entry to the .gitignore so that your local Git ignores them.

/**
* Name of shared map
*/
private static final String MY_JOBS_QUEUE = "jobs-queue";

Choose a reason for hiding this comment

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

It's fine if you like, but static field names don't need to start with "my" (only instance fields). Just FYI.

You could also change the visibility to public so that the test could directly reference it rather than redefine it 🤷🏻


// Associate handlers with operation IDs from the application's OpenAPI specification
routerBuilder.operation(Op.GET_STATUS).handler(new StatusHandler(getVertx()));
//add for JobsStatusHandler

Choose a reason for hiding this comment

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

Assuming this is a "to-do", it would be good to explicitly mark it as such by prefixing with TODO (you may have noticed that many IDEs automatically aggregate such comments in a special "problems" area of their UI).

Comment on lines -32 to +35
assertEquals(PATH_ROOT, new CsvItem().setPathRoot(SOUL_WAV).getPathRoot());
final CsvItem csvItem = new CsvItem();

csvItem.setPathRoot(PATH_ROOT);
assertEquals(PATH_ROOT, csvItem.getPathRoot());

Choose a reason for hiding this comment

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

Why the change in argument passed to setPathRoot?

Comment on lines +38 to +42
/*
* A smaller sample audio CSV
*/
public static final String SOUL_SAMPLE = "job_map_test.csv";

Choose a reason for hiding this comment

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

Did you mean to check in a new CSV?



/**
* An abstract test that other tests can extend.

Choose a reason for hiding this comment

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

Javadoc needs updating

Comment on lines +110 to +111
myJobsQueue.addJobToQueue(item);

Choose a reason for hiding this comment

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

I think this statement is misplaced. Here, it will be executed when all of the tasks in the futures List succeed (i.e., after all the jobs have finished). IMO, it should be at the end of the lambda passed to reader.readBeans().forEach(...) above.

Comment on lines +216 to +218

myJobsQueue.removeJobInQueue(ark);

Choose a reason for hiding this comment

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

Wondering if this one is also misplaced. Is there a reason not to run this for each record (i.e., unconditionally in each loop iteration)?

Comment on lines +119 to +131
jobsMap.put(ARK_REM, aItem, result -> {
if (result.failed()) {
aContext.fail(result.cause());
}
});

final Future<Void> future = JobsQueue.removeJobInQueue(ARK_REM);
jobsMap.get(ARK_REM).onFailure(failure -> {
aContext.fail();
}).onSuccess(res -> {
assertEquals(res, null);
asyncTask.complete();
});
Copy link

@markmatney markmatney Mar 22, 2023

Choose a reason for hiding this comment

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

In this special case, these three async tasks (jobsMap.put, JobsQueue.removeJobInQueue, jobsMap.get) get coordinated properly, but that's just because they happen to use the same nice and lawful Vert.x core asynchronous API all the way down: the operations are very fast, so the order in which they start happens to be the same as the order in which they finish. This will not be the case in general though (for example, if you have an async method that runs some long blocking I/O on a worker thread). So I'd argue it's always preferable to explicitly coordinate async stuff:

Suggested change
jobsMap.put(ARK_REM, aItem, result -> {
if (result.failed()) {
aContext.fail(result.cause());
}
});
final Future<Void> future = JobsQueue.removeJobInQueue(ARK_REM);
jobsMap.get(ARK_REM).onFailure(failure -> {
aContext.fail();
}).onSuccess(res -> {
assertEquals(res, null);
asyncTask.complete();
});
jobsMap.put(ARK_REM, aItem, result -> {
if (result.failed()) {
aContext.fail(result.cause());
} else {
JobsQueue.removeJobInQueue(ARK_REM).compose(nil -> {
return jobsMap.get(ARK_REM);
}).onFailure(details -> {
aContext.fail(details); // Also, passing in the failure cause is a good idea
}).onSuccess(res -> {
assertEquals(null, res); // Also also, the expected value should always go first
asyncTask.complete();
});
});
});

To be fair, this is really cumbersome since the void-returning async methods are all that's available with these older versions of Vert.x.

Choose a reason for hiding this comment

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

Oh, I just realized this app uses Vert.x 4, in which case you could use the Future-returning versions if you wanted Javadocs in case you're interested:

@angelahuqing angelahuqing changed the title Serv 505 SERV-505 Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants