@@ -0,0 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [A Guide to JGit](http://www.baeldung.com/jgit)
|
||||
@@ -0,0 +1,58 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mabsisa</groupId>
|
||||
<artifactId>Twitter4J</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Twitter4J</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.twitter4j</groupId>
|
||||
<artifactId>twitter4j-core</artifactId>
|
||||
<version>4.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.twitter4j</groupId>
|
||||
<artifactId>twitter4j-stream</artifactId>
|
||||
<version>4.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/ApplicationTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.baeldung;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import twitter4j.DirectMessage;
|
||||
import twitter4j.Query;
|
||||
import twitter4j.QueryResult;
|
||||
import twitter4j.StallWarning;
|
||||
import twitter4j.Status;
|
||||
import twitter4j.StatusDeletionNotice;
|
||||
import twitter4j.StatusListener;
|
||||
import twitter4j.Twitter;
|
||||
import twitter4j.TwitterException;
|
||||
import twitter4j.TwitterFactory;
|
||||
import twitter4j.TwitterStream;
|
||||
import twitter4j.TwitterStreamFactory;
|
||||
import twitter4j.conf.ConfigurationBuilder;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static Twitter getTwitterinstance() {
|
||||
/**
|
||||
* if not using properties file, we can set access token by following way
|
||||
*/
|
||||
// ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
// cb.setDebugEnabled(true)
|
||||
// .setOAuthConsumerKey("DPHTBsWWO42d8rzshxlK0OwSY")
|
||||
// .setOAuthConsumerSecret("ACLXkeRY98NiaVCG1ai8fdYt0GoEGJbFeTuxjulSCO7sLKqls1")
|
||||
// .setOAuthAccessToken("838080188214759428-9MSK1ddPTN5ZZHbddjFI7s75mYgmCFQ")
|
||||
// .setOAuthAccessTokenSecret("1eXAADpHShAzQh5hGWLBUQHLysOuAKIOapmQQ8U0OVk2c");
|
||||
//
|
||||
// TwitterFactory tf = new TwitterFactory(cb.build());
|
||||
// Twitter twitter = tf.getSingleton();
|
||||
|
||||
Twitter twitter = TwitterFactory.getSingleton();
|
||||
return twitter;
|
||||
|
||||
}
|
||||
|
||||
public static String createTweet(String tweet) throws TwitterException {
|
||||
Twitter twitter = getTwitterinstance();
|
||||
Status status = twitter.updateStatus("creating baeldung API");
|
||||
return status.getText();
|
||||
}
|
||||
|
||||
public static List<String> getTimeLine() throws TwitterException {
|
||||
Twitter twitter = getTwitterinstance();
|
||||
List<Status> statuses = twitter.getHomeTimeline();
|
||||
return statuses.stream().map(
|
||||
item -> item.getText()).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
|
||||
public static String sendDirectMessage(String recipientName, String msg) throws TwitterException {
|
||||
Twitter twitter = getTwitterinstance();
|
||||
DirectMessage message = twitter.sendDirectMessage(recipientName, msg);
|
||||
return message.getText();
|
||||
}
|
||||
|
||||
public static List<String> searchtweets() throws TwitterException {
|
||||
Twitter twitter = getTwitterinstance();
|
||||
Query query = new Query("source:twitter4j baeldung");
|
||||
QueryResult result = twitter.search(query);
|
||||
List<Status> statuses = result.getTweets();
|
||||
return statuses.stream().map(
|
||||
item -> item.getText()).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
|
||||
public static void streamFeed() {
|
||||
|
||||
StatusListener listener = new StatusListener(){
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeletionNotice(StatusDeletionNotice arg) {
|
||||
System.out.println("Got a status deletion notice id:" + arg.getStatusId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrubGeo(long userId, long upToStatusId) {
|
||||
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStallWarning(StallWarning warning) {
|
||||
System.out.println("Got stall warning:" + warning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatus(Status status) {
|
||||
System.out.println(status.getUser().getName() + " : " + status.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
|
||||
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
|
||||
}
|
||||
};
|
||||
|
||||
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
|
||||
|
||||
twitterStream.addListener(listener);
|
||||
|
||||
twitterStream.sample();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
oauth.consumerKey=//TODO
|
||||
oauth.consumerSecret=//TODO
|
||||
oauth.accessToken=//TODO
|
||||
oauth.accessTokenSecret=//TODO
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.baeldung;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
public class ApplicationTest {
|
||||
|
||||
/**
|
||||
* In order run this jUnit test you need to configure your API details in the twitter4j.properties
|
||||
*/
|
||||
|
||||
String tweet = "baeldung is awsome";
|
||||
|
||||
@Test
|
||||
public void givenText_updateStatus() throws TwitterException {
|
||||
String text = Application.createTweet(tweet);
|
||||
assertEquals(tweet, text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCredential_fetchStatus() throws TwitterException {
|
||||
List<String> statuses = Application.getTimeLine();
|
||||
List<String> expectedStatuses = new ArrayList<String>();
|
||||
expectedStatuses.add(tweet);
|
||||
assertEquals(expectedStatuses, statuses);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRecipientNameAndMessage_sendDirectMessage() throws TwitterException {
|
||||
String msg = Application.sendDirectMessage("YOUR_RECCIPIENT_ID", tweet);
|
||||
assertEquals(msg, tweet);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra)
|
||||
- [Introduction to Cobertura](http://www.baeldung.com/cobertura)
|
||||
+20
-1
@@ -41,4 +41,23 @@
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<instrumentation>
|
||||
<ignores>
|
||||
<ignore>com/baeldung/algorithms/dijkstra/*</ignore>
|
||||
</ignores>
|
||||
<excludes>
|
||||
<exclude>com/baeldung/algorithms/dijkstra/*</exclude>
|
||||
</excludes>
|
||||
</instrumentation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Intro to Apache BVal](http://www.baeldung.com/apache-bval)
|
||||
@@ -0,0 +1,36 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-commons</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<compiler.version>3.6.0</compiler.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.baeldung.commons.lang3;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class ArrayUtilsTest {
|
||||
@Test
|
||||
public void givenArray_whenAddingElementAtSpecifiedPosition_thenCorrect() {
|
||||
int[] oldArray = { 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.add(oldArray, 0, 1);
|
||||
int[] expectedArray = { 1, 2, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenAddingElementAtTheEnd_thenCorrect() {
|
||||
int[] oldArray = { 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.add(oldArray, 1);
|
||||
int[] expectedArray = { 2, 3, 4, 5, 1 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenAddingAllElementsAtTheEnd_thenCorrect() {
|
||||
int[] oldArray = { 0, 1, 2 };
|
||||
int[] newArray = ArrayUtils.addAll(oldArray, 3, 4, 5);
|
||||
int[] expectedArray = { 0, 1, 2, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingElementAtSpecifiedPosition_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.remove(oldArray, 1);
|
||||
int[] expectedArray = { 1, 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAllElementsAtSpecifiedPositions_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.removeAll(oldArray, 1, 3);
|
||||
int[] expectedArray = { 1, 3, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAnElement_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 3, 3, 4 };
|
||||
int[] newArray = ArrayUtils.removeElement(oldArray, 3);
|
||||
int[] expectedArray = { 1, 2, 3, 4 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingElements_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 3, 3, 4 };
|
||||
int[] newArray = ArrayUtils.removeElements(oldArray, 2, 3, 5);
|
||||
int[] expectedArray = { 1, 3, 4 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenRemovingAllElementOccurences_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 2, 2, 3 };
|
||||
int[] newArray = ArrayUtils.removeAllOccurences(oldArray, 2);
|
||||
int[] expectedArray = { 1, 3 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenCheckingExistingElement_thenCorrect() {
|
||||
int[] array = { 1, 3, 5, 7, 9 };
|
||||
boolean evenContained = ArrayUtils.contains(array, 2);
|
||||
boolean oddContained = ArrayUtils.contains(array, 7);
|
||||
assertEquals(false, evenContained);
|
||||
assertEquals(true, oddContained);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenReversingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.reverse(originalArray, 1, 4);
|
||||
int[] expectedArray = { 1, 4, 3, 2, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenReversingAllElements_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.reverse(originalArray);
|
||||
int[] expectedArray = { 5, 4, 3, 2, 1 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenShiftingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.shift(originalArray, 1, 4, 1);
|
||||
int[] expectedArray = { 1, 4, 2, 3, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenShiftingAllElements_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.shift(originalArray, 1);
|
||||
int[] expectedArray = { 5, 1, 2, 3, 4 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenExtractingElements_thenCorrect() {
|
||||
int[] oldArray = { 1, 2, 3, 4, 5 };
|
||||
int[] newArray = ArrayUtils.subarray(oldArray, 2, 7);
|
||||
int[] expectedArray = { 3, 4, 5 };
|
||||
assertArrayEquals(expectedArray, newArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenSwapingElementsWithinARange_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.swap(originalArray, 0, 3, 2);
|
||||
int[] expectedArray = { 4, 5, 3, 1, 2 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArray_whenSwapingElementsAtSpecifiedPositions_thenCorrect() {
|
||||
int[] originalArray = { 1, 2, 3, 4, 5 };
|
||||
ArrayUtils.swap(originalArray, 0, 3);
|
||||
int[] expectedArray = { 4, 2, 3, 1, 5 };
|
||||
assertArrayEquals(expectedArray, originalArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.baeldung.commons.lang3;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class StringUtilsTest {
|
||||
@Test
|
||||
public void givenString_whenCheckingContainsAny_thenCorrect() {
|
||||
String string = "baeldung.com";
|
||||
boolean contained1 = StringUtils.containsAny(string, 'a', 'b', 'c');
|
||||
boolean contained2 = StringUtils.containsAny(string, 'x', 'y', 'z');
|
||||
boolean contained3 = StringUtils.containsAny(string, "abc");
|
||||
boolean contained4 = StringUtils.containsAny(string, "xyz");
|
||||
assertTrue(contained1);
|
||||
assertFalse(contained2);
|
||||
assertTrue(contained3);
|
||||
assertFalse(contained4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenCheckingContainsIgnoreCase_thenCorrect() {
|
||||
String string = "baeldung.com";
|
||||
boolean contained = StringUtils.containsIgnoreCase(string, "BAELDUNG");
|
||||
assertTrue(contained);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenCountingMatches_thenCorrect() {
|
||||
String string = "welcome to www.baeldung.com";
|
||||
int charNum = StringUtils.countMatches(string, 'w');
|
||||
int stringNum = StringUtils.countMatches(string, "com");
|
||||
assertEquals(4, charNum);
|
||||
assertEquals(2, stringNum);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenAppendingAndPrependingIfMissing_thenCorrect() {
|
||||
String string = "baeldung.com";
|
||||
String stringWithSuffix = StringUtils.appendIfMissing(string, ".com");
|
||||
String stringWithPrefix = StringUtils.prependIfMissing(string, "www.");
|
||||
assertEquals("baeldung.com", stringWithSuffix);
|
||||
assertEquals("www.baeldung.com", stringWithPrefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenSwappingCase_thenCorrect() {
|
||||
String originalString = "baeldung.COM";
|
||||
String swappedString = StringUtils.swapCase(originalString);
|
||||
assertEquals("BAELDUNG.com", swappedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenCapitalizing_thenCorrect() {
|
||||
String originalString = "baeldung";
|
||||
String capitalizedString = StringUtils.capitalize(originalString);
|
||||
assertEquals("Baeldung", capitalizedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUncapitalizing_thenCorrect() {
|
||||
String originalString = "Baeldung";
|
||||
String uncapitalizedString = StringUtils.uncapitalize(originalString);
|
||||
assertEquals("baeldung", uncapitalizedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenReversingCharacters_thenCorrect() {
|
||||
String originalString = "baeldung";
|
||||
String reversedString = StringUtils.reverse(originalString);
|
||||
assertEquals("gnudleab", reversedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenReversingWithDelimiter_thenCorrect() {
|
||||
String originalString = "www.baeldung.com";
|
||||
String reversedString = StringUtils.reverseDelimited(originalString, '.');
|
||||
assertEquals("com.baeldung.www", reversedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenRotatingTwoPositions_thenCorrect() {
|
||||
String originalString = "baeldung";
|
||||
String rotatedString = StringUtils.rotate(originalString, 4);
|
||||
assertEquals("dungbael", rotatedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoStrings_whenComparing_thenCorrect() {
|
||||
String tutorials = "Baeldung Tutorials";
|
||||
String courses = "Baeldung Courses";
|
||||
String diff1 = StringUtils.difference(tutorials, courses);
|
||||
String diff2 = StringUtils.difference(courses, tutorials);
|
||||
assertEquals("Courses", diff1);
|
||||
assertEquals("Tutorials", diff2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
## Apache Solrj Tutorials Project
|
||||
|
||||
### Relevant Articles
|
||||
- [Guide to Solr in Java with Apache Solrj](http://www.baeldung.com/apache-solrj)
|
||||
@@ -0,0 +1,50 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-solrj</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>apache-solrj</name>
|
||||
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.solr</groupId>
|
||||
<artifactId>solr-solrj</artifactId>
|
||||
<version>6.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.solrjava;
|
||||
|
||||
import org.apache.solr.client.solrj.beans.Field;
|
||||
|
||||
public class ProductBean {
|
||||
|
||||
String id;
|
||||
String name;
|
||||
String price;
|
||||
|
||||
public ProductBean(String id, String name, String price) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Field("id")
|
||||
protected void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Field("name")
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Field("price")
|
||||
protected void setPrice(String price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.baeldung.solrjava;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
||||
public class SolrJavaIntegration {
|
||||
|
||||
private HttpSolrClient solrClient;
|
||||
|
||||
public SolrJavaIntegration(String clientUrl) {
|
||||
|
||||
solrClient = new HttpSolrClient.Builder(clientUrl).build();
|
||||
solrClient.setParser(new XMLResponseParser());
|
||||
}
|
||||
|
||||
public void addProductBean(ProductBean pBean) throws IOException, SolrServerException {
|
||||
|
||||
solrClient.addBean(pBean);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
public void addSolrDocument(String documentId, String itemName, String itemPrice) throws SolrServerException, IOException {
|
||||
|
||||
SolrInputDocument document = new SolrInputDocument();
|
||||
document.addField("id", documentId);
|
||||
document.addField("name", itemName);
|
||||
document.addField("price", itemPrice);
|
||||
solrClient.add(document);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
public void deleteSolrDocumentById(String documentId) throws SolrServerException, IOException {
|
||||
|
||||
solrClient.deleteById(documentId);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
public void deleteSolrDocumentByQuery(String query) throws SolrServerException, IOException {
|
||||
|
||||
solrClient.deleteByQuery(query);
|
||||
solrClient.commit();
|
||||
}
|
||||
|
||||
protected HttpSolrClient getSolrClient() {
|
||||
return solrClient;
|
||||
}
|
||||
|
||||
protected void setSolrClient(HttpSolrClient solrClient) {
|
||||
this.solrClient = solrClient;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.baeldung.solrjava;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
import org.apache.solr.common.SolrDocument;
|
||||
import org.apache.solr.common.SolrDocumentList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SolrJavaIntegrationTest {
|
||||
|
||||
private SolrJavaIntegration solrJavaIntegration;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
solrJavaIntegration = new SolrJavaIntegration("http://localhost:8983/solr/bigboxstore");
|
||||
solrJavaIntegration.addSolrDocument("123456", "Kenmore Dishwasher", "599.99");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAdd_thenVerifyAddedByQueryOnId() throws SolrServerException, IOException {
|
||||
|
||||
SolrQuery query = new SolrQuery();
|
||||
query.set("q", "id:123456");
|
||||
QueryResponse response = null;
|
||||
|
||||
response = solrJavaIntegration.getSolrClient().query(query);
|
||||
|
||||
SolrDocumentList docList = response.getResults();
|
||||
assertEquals(1, docList.getNumFound());
|
||||
|
||||
for (SolrDocument doc : docList) {
|
||||
assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name"));
|
||||
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAdd_thenVerifyAddedByQueryOnPrice() throws SolrServerException, IOException {
|
||||
|
||||
SolrQuery query = new SolrQuery();
|
||||
query.set("q", "price:599.99");
|
||||
QueryResponse response = null;
|
||||
|
||||
response = solrJavaIntegration.getSolrClient().query(query);
|
||||
|
||||
SolrDocumentList docList = response.getResults();
|
||||
assertEquals(1, docList.getNumFound());
|
||||
|
||||
for (SolrDocument doc : docList) {
|
||||
assertEquals("123456", (String) doc.getFieldValue("id"));
|
||||
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAdd_thenVerifyAddedByQuery() throws SolrServerException, IOException {
|
||||
|
||||
SolrDocument doc = solrJavaIntegration.getSolrClient().getById("123456");
|
||||
assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name"));
|
||||
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddBean_thenVerifyAddedByQuery() throws SolrServerException, IOException {
|
||||
|
||||
ProductBean pBean = new ProductBean("888", "Apple iPhone 6s", "299.99");
|
||||
solrJavaIntegration.addProductBean(pBean);
|
||||
|
||||
SolrDocument doc = solrJavaIntegration.getSolrClient().getById("888");
|
||||
assertEquals("Apple iPhone 6s", (String) doc.getFieldValue("name"));
|
||||
assertEquals((Double) 299.99, (Double) doc.getFieldValue("price"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeleteById_thenVerifyDeleted() throws SolrServerException, IOException {
|
||||
|
||||
solrJavaIntegration.deleteSolrDocumentById("123456");
|
||||
|
||||
SolrQuery query = new SolrQuery();
|
||||
query.set("q", "id:123456");
|
||||
QueryResponse response = solrJavaIntegration.getSolrClient().query(query);
|
||||
|
||||
SolrDocumentList docList = response.getResults();
|
||||
assertEquals(0, docList.getNumFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeleteByQuery_thenVerifyDeleted() throws SolrServerException, IOException {
|
||||
|
||||
solrJavaIntegration.deleteSolrDocumentByQuery("name:Kenmore Dishwasher");
|
||||
|
||||
SolrQuery query = new SolrQuery();
|
||||
query.set("q", "id:123456");
|
||||
QueryResponse response = null;
|
||||
|
||||
response = solrJavaIntegration.getSolrClient().query(query);
|
||||
|
||||
SolrDocumentList docList = response.getResults();
|
||||
assertEquals(0, docList.getNumFound());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Working with Apache Thrift](http://www.baeldung.com/apache-thrift)
|
||||
@@ -0,0 +1,3 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Introduction to Apache Velocity](http://www.baeldung.com/apache-velocity)
|
||||
+22
-3
@@ -7,17 +7,36 @@
|
||||
<packaging>jar</packaging>
|
||||
<name>aws</name>
|
||||
|
||||
<properties>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -26,7 +45,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.lambda.dynamodb;
|
||||
|
||||
import com.amazonaws.regions.Region;
|
||||
import com.amazonaws.regions.Regions;
|
||||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
|
||||
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
|
||||
import com.amazonaws.services.dynamodbv2.document.Item;
|
||||
import com.amazonaws.services.dynamodbv2.document.PutItemOutcome;
|
||||
import com.amazonaws.services.dynamodbv2.document.spec.PutItemSpec;
|
||||
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
import com.baeldung.lambda.dynamodb.bean.PersonRequest;
|
||||
import com.baeldung.lambda.dynamodb.bean.PersonResponse;
|
||||
|
||||
public class SavePersonHandler implements RequestHandler<PersonRequest, PersonResponse> {
|
||||
|
||||
private DynamoDB dynamoDb;
|
||||
|
||||
private String DYNAMODB_TABLE_NAME = "Person";
|
||||
private Regions REGION = Regions.US_WEST_2;
|
||||
|
||||
public PersonResponse handleRequest(PersonRequest personRequest, Context context) {
|
||||
this.initDynamoDbClient();
|
||||
|
||||
persistData(personRequest);
|
||||
|
||||
PersonResponse personResponse = new PersonResponse();
|
||||
personResponse.setMessage("Saved Successfully!!!");
|
||||
return personResponse;
|
||||
}
|
||||
|
||||
private PutItemOutcome persistData(PersonRequest personRequest) throws ConditionalCheckFailedException {
|
||||
return this.dynamoDb.getTable(DYNAMODB_TABLE_NAME)
|
||||
.putItem(
|
||||
new PutItemSpec().withItem(new Item()
|
||||
.withNumber("id", personRequest.getId())
|
||||
.withString("firstName", personRequest.getFirstName())
|
||||
.withString("lastName", personRequest.getLastName())
|
||||
.withNumber("age", personRequest.getAge())
|
||||
.withString("address", personRequest.getAddress())));
|
||||
}
|
||||
|
||||
private void initDynamoDbClient() {
|
||||
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
|
||||
client.setRegion(Region.getRegion(REGION));
|
||||
this.dynamoDb = new DynamoDB(client);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.baeldung.lambda.dynamodb.bean;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class PersonRequest {
|
||||
private int id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private int age;
|
||||
private String address;
|
||||
|
||||
public static void main(String[] args) {
|
||||
PersonRequest personRequest = new PersonRequest();
|
||||
personRequest.setId(1);
|
||||
personRequest.setFirstName("John");
|
||||
personRequest.setLastName("Doe");
|
||||
personRequest.setAge(30);
|
||||
personRequest.setAddress("United States");
|
||||
System.out.println(personRequest);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.lambda.dynamodb.bean;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class PersonResponse {
|
||||
private String message;
|
||||
|
||||
public String toString() {
|
||||
final Gson gson = new Gson();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,5 @@
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java 9 Stream API Improvements](http://www.baeldung.com/java-9-stream-api)
|
||||
- [Java 9 Convenience Factory Methods for Collections](http://www.baeldung.com/java-9-collections-factory-methods)
|
||||
- [New Stream Collectors in Java 9](http://www.baeldung.com/java9-stream-collectors)
|
||||
|
||||
+7
-2
@@ -21,6 +21,11 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${ch.qos.logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
@@ -76,9 +81,9 @@
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
|
||||
<ch.qos.logback.version>1.2.1</ch.qos.logback.version>
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
|
||||
<!-- testing -->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java8;
|
||||
package com.baeldung.java9;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Java9OptionalsStreamTest {
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.baeldung.java9.process;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by sanaulla on 2/23/2017.
|
||||
*/
|
||||
|
||||
public class ProcessAPIEnhancementsTest {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(ProcessAPIEnhancementsTest.class);
|
||||
|
||||
@Test
|
||||
public void givenCurrentProcess_whenInvokeGetInfo_thenSuccess() throws IOException {
|
||||
ProcessHandle processHandle = ProcessHandle.current();
|
||||
ProcessHandle.Info processInfo = processHandle.info();
|
||||
assertNotNull(processHandle.getPid());
|
||||
assertEquals(false, processInfo.arguments()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.command()
|
||||
.isPresent());
|
||||
assertTrue(processInfo.command()
|
||||
.get()
|
||||
.contains("java"));
|
||||
|
||||
assertEquals(true, processInfo.startInstant()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.totalCpuDuration()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.user()
|
||||
.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSpawnProcess_whenInvokeGetInfo_thenSuccess() throws IOException {
|
||||
|
||||
String javaCmd = ProcessUtils.getJavaCmd()
|
||||
.getAbsolutePath();
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(javaCmd, "-version");
|
||||
Process process = processBuilder.inheritIO()
|
||||
.start();
|
||||
ProcessHandle processHandle = process.toHandle();
|
||||
ProcessHandle.Info processInfo = processHandle.info();
|
||||
assertNotNull(processHandle.getPid());
|
||||
assertEquals(false, processInfo.arguments()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.command()
|
||||
.isPresent());
|
||||
assertTrue(processInfo.command()
|
||||
.get()
|
||||
.contains("java"));
|
||||
assertEquals(true, processInfo.startInstant()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.totalCpuDuration()
|
||||
.isPresent());
|
||||
assertEquals(true, processInfo.user()
|
||||
.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLiveProcesses_whenInvokeGetInfo_thenSuccess() {
|
||||
Stream<ProcessHandle> liveProcesses = ProcessHandle.allProcesses();
|
||||
liveProcesses.filter(ProcessHandle::isAlive)
|
||||
.forEach(ph -> {
|
||||
assertNotNull(ph.getPid());
|
||||
assertEquals(true, ph.info()
|
||||
.command()
|
||||
.isPresent());
|
||||
assertEquals(true, ph.info()
|
||||
.startInstant()
|
||||
.isPresent());
|
||||
assertEquals(true, ph.info()
|
||||
.totalCpuDuration()
|
||||
.isPresent());
|
||||
assertEquals(true, ph.info()
|
||||
.user()
|
||||
.isPresent());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcess_whenGetChildProcess_thenSuccess() throws IOException {
|
||||
int childProcessCount = 5;
|
||||
for (int i = 0; i < childProcessCount; i++) {
|
||||
String javaCmd = ProcessUtils.getJavaCmd()
|
||||
.getAbsolutePath();
|
||||
ProcessBuilder processBuilder
|
||||
= new ProcessBuilder(javaCmd, "-version");
|
||||
processBuilder.inheritIO().start();
|
||||
}
|
||||
|
||||
Stream<ProcessHandle> children = ProcessHandle.current()
|
||||
.children();
|
||||
children.filter(ProcessHandle::isAlive)
|
||||
.forEach(ph -> log.info("PID: {}, Cmd: {}", ph.getPid(), ph.info()
|
||||
.command()));
|
||||
Stream<ProcessHandle> descendants = ProcessHandle.current()
|
||||
.descendants();
|
||||
descendants.filter(ProcessHandle::isAlive)
|
||||
.forEach(ph -> log.info("PID: {}, Cmd: {}", ph.getPid(), ph.info()
|
||||
.command()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcess_whenAddExitCallback_thenSuccess() throws Exception {
|
||||
String javaCmd = ProcessUtils.getJavaCmd()
|
||||
.getAbsolutePath();
|
||||
ProcessBuilder processBuilder
|
||||
= new ProcessBuilder(javaCmd, "-version");
|
||||
Process process = processBuilder.inheritIO()
|
||||
.start();
|
||||
ProcessHandle processHandle = process.toHandle();
|
||||
|
||||
log.info("PID: {} has started", processHandle.getPid());
|
||||
CompletableFuture<ProcessHandle> onProcessExit = processHandle.onExit();
|
||||
onProcessExit.get();
|
||||
assertEquals(false, processHandle.isAlive());
|
||||
onProcessExit.thenAccept(ph -> {
|
||||
log.info("PID: {} has stopped", ph.getPid());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
*.class
|
||||
|
||||
0.*
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
.resourceCache
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user