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

393-js-publish-async and utils / tests / misc #398

Merged
merged 10 commits into from
Jan 26, 2021
Merged

393-js-publish-async and utils / tests / misc #398

merged 10 commits into from
Jan 26, 2021

Conversation

scottf
Copy link
Contributor

@scottf scottf commented Jan 19, 2021

Misc changes and attempt at #393

.name(streamName)
.storageType(storageType)
.subjects(subject)
.build();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

convention is to put the dot at the beginning. also when concatenating strings with + it goes at the beginning, or using && for multi line if. It makes it easier to comment out a line too.

}
return ea;
}

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 noticed that this was repeated so I refactored it.

CompletableFuture<PublishAck> publishAsync(String subject, byte[] body);
CompletableFuture<PublishAck> publishAsync(String subject, byte[] body, PublishOptions options);
CompletableFuture<PublishAck> publishAsync(Message message);
CompletableFuture<PublishAck> publishAsync(Message message, PublishOptions options);
Copy link
Contributor Author

@scottf scottf Jan 19, 2021

Choose a reason for hiding this comment

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

This for #393

Copy link
Member

Choose a reason for hiding this comment

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

Looks good, just needs comments.

@scottf scottf changed the title Utils tests misc 393-js-publish-async and utils / tests / misc Jan 19, 2021
@@ -438,7 +432,7 @@ static DecodedSeed decodeSeed(char[] seed) {
private static NKey createPair(Type type, SecureRandom random)
throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
if (random == null) {
random = new SecureRandom();
random = SRAND;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

shared secure random

private static final String QCOLONQ = "\": \"";
private static final String QCOLON = "\": ";
private static final String QCOLONQ = "\":\"";
private static final String QCOLON = "\":";
Copy link
Contributor Author

@scottf scottf Jan 19, 2021

Choose a reason for hiding this comment

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

Space is not required. Not need to send extra bytes

@@ -65,22 +66,22 @@
AccountLimitImpl(String json) {
Matcher m = LIMITS_MEMORY_RE.matcher(json);
if (m.find()) {
this.memory = Integer.parseInt(m.group(1));
this.memory = Long.parseLong(m.group(1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the long parser since the variables are long.

}
});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This for #393

import java.security.SecureRandom;
import java.util.Random;

public abstract class RandomUtils {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Utils provides shared random. Both Random and Secure random are thread-safe.

}

private static StreamInfo createMemoryStream(JetStream js, String streamName, String[] subjects)
private static StreamInfo createMemoryStream(JetStream js, String streamName, String... subjects)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This signature will accept one (zero actually) or more strings, so we don't need 2 methods

Assertions.fail("Exception: " + ex.getMessage());
} finally {
nc.close();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. If an exception is throw the test will fail naturally, so no need to check for it.
  2. Finally to close the connection is not required since Connection implements AutoCloseable and the object is created via the try, the close happens automatically.

// check success
opts.setExpectedStream("foo-stream");
opts.setExpectedLastSeqence(PublishOptions.unsetLastSequence);
js.publish("foo", null, opts);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this now passes since the server is fixed.

catch (IllegalStateException ise) {
System.out.println(ise.getMessage());
}
/*
Copy link
Member

Choose a reason for hiding this comment

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

Did you intend to leave this in?


package io.nats.client;

// TODO
Copy link
Member

Choose a reason for hiding this comment

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

Need class comment...

MAINTAINERS.md Outdated
@@ -8,3 +8,4 @@ Maintainership is on a per project basis.
- Colin Sullivan <colin@nats.io> [@ColinSullivan1](https://github.com/ColinSullivan1)
- Derek Collison <derek@nats.io> [@derekcollison](https://github.com/derekcollison)
- Ivan Kozlovic <ivan@nats.io> [@kozlovic](https://github.com/kozlovic)
- Scott Fauerbach <scott@nats.io> [@scottf](https://github.com/scottf)
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately we can't do this right now. We need a formal vote to add you as a Maintainer per NATS Governance. We'll certainly revisit 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.

ok sorry, will remove

action("Make And Use Subscription");
SubscribeOptions so = SubscribeOptions.builder()
.pullDirect(STREAM1, "GQJ3IvWo", 10)
// .configuration(STREAM1, cc)
Copy link
Member

Choose a reason for hiding this comment

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

Intended to 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.

This is an example that I have not finished

}

private static void action(String label) {
System.out.println("================================================================================");
Copy link
Member

Choose a reason for hiding this comment

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

Looks like an issue with spacing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just debug stuff using to show what's going on

*/
PublishAck publish(Message message, PublishOptions options) throws IOException, JetStreamApiException;

CompletableFuture<PublishAck> publishAsync(String subject, byte[] body);
Copy link
Member

Choose a reason for hiding this comment

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

Needs comments...


package io.nats.client.impl;

public class JetStreamApiException extends Exception {
Copy link
Member

Choose a reason for hiding this comment

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

This class and methods will need doc... may not make it through travis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will comment for next PR


private Message makeRequest(NatsMessage natsMessage, Duration timeout) throws IOException {
try {
return responseRequired(conn.request(natsMessage, timeout));
Copy link
Member

Choose a reason for hiding this comment

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

I think this'll miss the prefix...

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

Lots of work here! LGTM so far - a few comments on docs, etc.

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

Per offline discussion, after comments are added LGTM. Feel free to merge..

@scottf scottf merged commit ce1c050 into nats-io:master Jan 26, 2021
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.

None yet

2 participants