Skip to content

Commit

Permalink
Upgrade to Spring Boot 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pavankjadda committed Dec 4, 2020
1 parent d4b0e05 commit 30678bc
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 271 deletions.
30 changes: 13 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.kafkastream</groupId>
<artifactId>kafkastream</artifactId>
<version>1.5</version>
<version>1.6</version>
<packaging>jar</packaging>

<name>KafkaStream</name>
Expand All @@ -14,26 +14,26 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<version>2.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version>
<avro.version>1.9.2</avro.version>
<java.version>11</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<avro.version>1.10.0</avro.version>
<kafka.version>2.1.0</kafka.version>
<confluent.version>5.4.0</confluent.version>
<confluent.version>6.0.0</confluent.version>
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
</properties>

<dependencies>
<!-- Spring Dependencies-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -66,11 +66,7 @@
<artifactId>kafka-streams-avro-serde</artifactId>
<version>${confluent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>${kafka.version}</version>
</dependency>

<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
Expand All @@ -87,18 +83,15 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.35.v20201120</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.26.v20200117</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand All @@ -116,12 +109,16 @@
<optional>true</optional>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.3</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
Expand All @@ -131,7 +128,6 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<version>1.4.194</version>
</dependency>

</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/kafkastream/events/EventsSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.kafkastream.model.Customer;
import com.kafkastream.model.Greetings;
import com.kafkastream.model.Order;
import io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig;
import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig;
import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde;
import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerializer;
import org.apache.avro.specific.SpecificRecord;
Expand All @@ -27,7 +27,7 @@
@Service
public class EventsSender
{
private Properties properties;
private final Properties properties;
private static final Logger logger= LoggerFactory.getLogger(EventsSender.class);

public EventsSender()
Expand Down Expand Up @@ -75,7 +75,7 @@ public void sendGreetingsEvent(Greetings greetings) throws ExecutionException, I
private static <VT extends SpecificRecord> SpecificAvroSerde<VT> createSerde()
{
final SpecificAvroSerde<VT> serde = new SpecificAvroSerde<>();
final Map<String, String> serdeConfig = Collections.singletonMap(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, KafkaConstants.SCHEMA_REGISTRY_URL);
final Map<String, String> serdeConfig = Collections.singletonMap(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, KafkaConstants.SCHEMA_REGISTRY_URL);
serde.configure(serdeConfig, false);
return serde;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,37 @@ public CustomRestTemplateService(RestTemplate restTemplate)
public List<Customer> getAllCustomers()
{
ResponseEntity<List<Customer>> response=restTemplate.exchange(REST_PROXY_HOST+":"+REST_PROXY_PORT+"/store/customers",
HttpMethod.GET,null, new ParameterizedTypeReference<List<Customer>>(){});
HttpMethod.GET,null, new ParameterizedTypeReference<>()
{
});
return response.getBody();
}

public List<Order> getAllOrders()
{
ResponseEntity<List<Order>> response=restTemplate.exchange(REST_PROXY_HOST+":"+REST_PROXY_PORT+"/store/orders",
HttpMethod.GET,null, new ParameterizedTypeReference<List<Order>>(){});
HttpMethod.GET,null, new ParameterizedTypeReference<>()
{
});
return response.getBody();
}

public List<Greetings> getAllGreetings()
{
ResponseEntity<List<Greetings>> response=restTemplate.exchange(REST_PROXY_HOST+":"+REST_PROXY_PORT+"/store/greetings",
HttpMethod.GET,null, new ParameterizedTypeReference<List<Greetings>>(){});
HttpMethod.GET,null, new ParameterizedTypeReference<>()
{
});
return response.getBody();
}

public List<CustomerOrder> getAllCustomersOrders()
{
ResponseEntity<List<CustomerOrder>> response=restTemplate.exchange(REST_PROXY_HOST+":"+REST_PROXY_PORT+"/store/customer" +
"-order/all",
HttpMethod.GET,null, new ParameterizedTypeReference<List<CustomerOrder>>(){});
HttpMethod.GET,null, new ParameterizedTypeReference<>()
{
});
return response.getBody();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.kafkastream;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class KafkaStreamApplicationTests {

Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/kafkastream/TestConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
import org.apache.kafka.streams.state.StoreBuilder;
import org.apache.kafka.streams.state.Stores;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


import java.util.Collections;
import java.util.HashMap;
Expand All @@ -43,7 +44,7 @@ public class TestConsumer

private StreamsBuilder streamsBuilder;

@Before
@BeforeEach
public void setUp()
{
this.properties = new Properties();
Expand Down Expand Up @@ -371,7 +372,7 @@ public void cleanStateStore()

//Not using this test case
@Test
@Ignore
@Disabled
public void queryCustomerStore()
{
SpecificAvroSerde<Customer> customerSerde = createSerde("http://localhost:8081");
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/kafkastream/TestProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.StreamsBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
Expand All @@ -27,7 +27,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class TestProducer
class TestProducer
{
@Autowired
private EventsSender eventsSender;
Expand All @@ -36,8 +36,8 @@ public class TestProducer

private StreamsBuilder streamsBuilder;

@Before
public void setUp()
@BeforeEach
void setUp()
{
//When configuring the default serdes of StreamConfig
properties = new Properties();
Expand All @@ -52,7 +52,7 @@ public void setUp()
}

@Test
public void sendCustomer() throws ExecutionException, InterruptedException
void sendCustomer() throws ExecutionException, InterruptedException
{
// When you want to override serdes explicitly/selectively
SpecificAvroSerde<Customer> customerSerde = createSerde("http://localhost:8081");
Expand All @@ -73,7 +73,7 @@ public void sendCustomer() throws ExecutionException, InterruptedException
}

@Test
public void sendOrder() throws ExecutionException, InterruptedException
void sendOrder() throws ExecutionException, InterruptedException
{
Random random = new Random(1);

Expand All @@ -96,7 +96,7 @@ public void sendOrder() throws ExecutionException, InterruptedException
}

@Test
public void sendCustomerAndOrder() throws ExecutionException, InterruptedException
void sendCustomerAndOrder() throws ExecutionException, InterruptedException
{
// When you want to override serdes explicitly/selectively
SpecificAvroSerde<Customer> customerSerde = createSerde("http://localhost:8081");
Expand Down
98 changes: 42 additions & 56 deletions src/test/java/com/kafkastream/jersey/Calculator.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
package com.kafkastream.jersey;

import lombok.Data;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Path("calculator")
public class Calculator {
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Result squareRoot(@QueryParam("input") double input){
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return result;
}

@GET
@Path("square")
@Produces(MediaType.APPLICATION_JSON)
public Result square(@QueryParam("input") double input){
Result result = new Result("Square");
result.setInput(input);
result.setOutput(result.getInput()*result.getInput());
return result;
}

static class Result{
double input;
double output;
String action;

public Result(){}

public Result(String action) {
this.action = action;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public double getInput() {
return input;
}

public void setInput(double input) {
this.input = input;
}

public double getOutput() {
return output;
}

public void setOutput(double output) {
this.output = output;
}
}
public class Calculator
{
@GET
@Path("squareRoot")
@Produces(MediaType.APPLICATION_JSON)
public Result squareRoot(@QueryParam("input") double input)
{
Result result = new Result("Square Root");
result.setInput(input);
result.setOutput(Math.sqrt(result.getInput()));
return result;
}

@GET
@Path("square")
@Produces(MediaType.APPLICATION_JSON)
public Result square(@QueryParam("input") double input)
{
Result result = new Result("Square");
result.setInput(input);
result.setOutput(result.getInput() * result.getInput());
return result;
}

@Data
static class Result
{
double input;
double output;
String action;

public Result()
{
}

public Result(String action)
{
this.action = action;
}
}
}
Loading

0 comments on commit 30678bc

Please sign in to comment.