Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,15 @@
package com.baeldung.failure_vs_error;
/**
* @author paullatzelsperger
* @since 2019-07-17
*/
public class SimpleCalculator {
public static double divideNumbers(double dividend, double divisor) {
if (divisor == 0) {
throw new ArithmeticException("Division by zero!");
}
return dividend / divisor;
}
}
@@ -0,0 +1,27 @@
package com.baeldung.junit5.testinstance;
import java.io.Serializable;
public class Tweet implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String content;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.junit5.testinstance;
public class TweetException extends RuntimeException {
private static final long serialVersionUID = 1L;
public TweetException(String message) {
super(message);
}
}
@@ -0,0 +1,41 @@
package com.baeldung.junit5.testinstance;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class TweetSerializer {
private static final int MAX_TWEET_SIZE = 1000;
private static final int MIN_TWEET_SIZE = 150;
private final Tweet tweet;
public TweetSerializer(Tweet tweet) {
this.tweet = tweet;
}
public byte[] serialize() throws IOException {
byte[] tweetContent = serializeTweet();
int totalLength = tweetContent.length;
validateSizeOfTweet(totalLength);
return tweetContent;
}
private void validateSizeOfTweet(int tweetSize) {
if (tweetSize > MAX_TWEET_SIZE) {
throw new TweetException("Tweet is too large");
}
if (tweetSize < MIN_TWEET_SIZE) {
throw new TweetException("Tweet is too small");
}
}
private byte[] serializeTweet() throws IOException {
try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectStream = new ObjectOutputStream(arrayOutputStream)) {
objectStream.writeObject(tweet);
return arrayOutputStream.toByteArray();
}
}
}