Skip to content

Small improvements related to types deprecation.#36328

Merged
jtibshirani merged 6 commits intoelastic:masterfrom
jtibshirani:refactor-types-deprecation
Dec 7, 2018
Merged

Small improvements related to types deprecation.#36328
jtibshirani merged 6 commits intoelastic:masterfrom
jtibshirani:refactor-types-deprecation

Conversation

@jtibshirani
Copy link
Copy Markdown
Contributor

  • Make sure to use deprecatedAndMaybeLog for types deprecation messages.
  • Introduce a common base class for Rest*Action tests.

@jtibshirani jtibshirani added >test Issues or PRs that are addressing/adding tests :Core/Infra/REST API REST infrastructure and utilities v7.0.0 labels Dec 6, 2018
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra

Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Nice! I left a small comment. I wonder if these is some way to clean up RestGetSourceActionTests. Could we make a method that makes the listener rather than set it up every time? That feels a little cleaner but I'm not sure.


import static org.mockito.Mockito.mock;

public abstract class RestActionTestCase extends ESTestCase {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great! Please add javadoc!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍


public void setUp() throws Exception {
super.setUp();
controller = new RestController(Collections.emptySet(), null,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is worth a comment about why these aren't final.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Are you imagining a comment like 'these are effectively final, but can't be marked as such because they're initialized in the @Before method`?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you declare the controller as final? I think it looks like it'd work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I caught up with @nik9000 offline and he is okay sticking with the style where we use @Before methods (and instance variables aren't final), instead of switching everything over to instance variables/ constructors. The reasoning is that there is an existing convention to use @Before methods in JUnit tests as opposed to standard object construction.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tend to use @Before as little as possible because it looks to me like a signal that I'm doing something complex. I see that this might be out of step with normal maven usage though. So I'm totally fine not doing it.

public abstract class RestActionTestCase extends ESTestCase {
private RestController controller;

public void setUp() throws Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is weird to override the superclass setup rather than make your own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I'm having trouble understanding the right alternative. This looked like a common approach in abstract classes that extend ESTestCase.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It comes up some times but other times we make a new @Before method instead. I think most of the time we make a @Before method. Unless we have specific ordering requirements between the method and the one of the superclass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

@jtibshirani
Copy link
Copy Markdown
Contributor Author

Thanks @nik9000 for the speedy code review! For RestGetSourceActionTests, could you explain a little more about what you were thinking? I didn't see a good way to pull more common functionality into RestActionTestCase, since the test is doing something fairly specific to 'get source' actions.

Copy link
Copy Markdown
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

Thanks Julie, your PR makes the code much shorter


public abstract class RestActionTestCase extends ESTestCase {
private RestController controller;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we add @Override above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now that we're creating new @Before methods, we should be able to avoid overriding setUp.

@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Dec 6, 2018

I didn't see a good way to pull more common functionality into RestActionTestCase, since the test is doing something fairly specific to 'get source' actions.

I don't think you should pull more common functionality into RestActionTestCase. I was more wondering if we needed the change there at all. Or, if we need it, could we continue to make them final and declared at the top? I think it is easier to understand what is going on when we avoid @Before methods that we don't absolutely need. Mostly because when I see a before method that doesn't look like we need it my brain flies off on a tangent trying to figure out why we have the method.

@jtibshirani
Copy link
Copy Markdown
Contributor Author

I was more wondering if we needed the change there at all.

Got it! I was used to a JUnit style where @Before is simply used in place of a constructor. So I thought this refactor was cleaning up RestGetSourceActionTests, but you actually found it confusing. I'll just revert this part of the PR, as it's not necessary.

if (searchRequest.types().length > 0) {
deprecationLogger.deprecated(RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE);
deprecationLogger.deprecatedAndMaybeLog("msearch_template_with_types",
RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to use RestMultiSearchTemplateAction here and the same with logger on line 44?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out @mayya-sharipova. If it's okay with you, I'll plan to fix this in another PR as this one is already reasonably large.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An update: I've fixed this in #36344.

@jtibshirani
Copy link
Copy Markdown
Contributor Author

jtibshirani commented Dec 6, 2018

After finding several additional instances of Rest*ActionTests that are outside of this package, I decided it would be good to scope this PR to just the test classes we've added to test types deprecation. That way I won't get pulled into a huge refactor, and we can make sure to have this base class available to others as they work on additional deprecations. @nik9000 @mayya-sharipova does this sound reasonable to you?

Here are the items I plan to follow up on in subsequent PRs:

  • Make sure RestMultiSearchTemplateAction uses the right class for logging and deprecation messages.
  • Refactor RestValidateQueryActionTests to simplify test set-up, and be able to use the base class RestActionTestCase.
  • Look into cleaning up other Rest*ActionTests by pulling them into the right package, unifying test set-up, etc.

@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Dec 7, 2018

scope this PR to just the test classes we've added to test types deprecation

Sounds good to me!

@jtibshirani
Copy link
Copy Markdown
Contributor Author

Thanks, in that case I think this is ready for another look!

Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM


public void setUp() throws Exception {
super.setUp();
controller = new RestController(Collections.emptySet(), null,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tend to use @Before as little as possible because it looks to me like a signal that I'm doing something complex. I see that this might be out of step with normal maven usage though. So I'm totally fine not doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/REST API REST infrastructure and utilities >test Issues or PRs that are addressing/adding tests v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants