#539 - Polishing.
Add author tags. Simplify dependency setup. Replace logger declarations with Lombok's CommonsLog. Simplify test annotations. Disable WAN module as the WAN server does not stop after running tests. Reformat code.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -29,6 +28,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
@Data
|
||||
public class Address implements Serializable {
|
||||
|
||||
private String street;
|
||||
private String city;
|
||||
private String country;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -55,4 +54,4 @@ public class Customer implements Serializable {
|
||||
public void add(Address address) {
|
||||
this.addresses.add(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -28,10 +27,11 @@ import java.io.Serializable;
|
||||
*/
|
||||
@Data
|
||||
public class EmailAddress implements Serializable {
|
||||
|
||||
private String value;
|
||||
|
||||
public EmailAddress(String value) {
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -41,4 +40,4 @@ public class LineItem implements Serializable {
|
||||
public BigDecimal calcTotal() {
|
||||
return product.getPrice().multiply(BigDecimal.valueOf(amount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.List;
|
||||
@Data
|
||||
@Region("Orders")
|
||||
public class Order implements Serializable {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private Long customerId;
|
||||
@@ -70,4 +71,4 @@ public class Order implements Serializable {
|
||||
public void add(LineItem lineItem) {
|
||||
lineItems.add(lineItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,18 +13,21 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@OnRegion(region = "Customers")
|
||||
public interface CustomerFunctionExecutions {
|
||||
|
||||
@FunctionId("listConsumersForEmailAddressesFnc")
|
||||
List<List<Customer>> listAllCustomersForEmailAddress(String... emailAddresses);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
|
||||
import org.springframework.data.gemfire.repository.Query;
|
||||
import org.springframework.data.gemfire.repository.query.annotation.Hint;
|
||||
@@ -24,8 +26,9 @@ import org.springframework.data.gemfire.repository.query.annotation.Limit;
|
||||
import org.springframework.data.gemfire.repository.query.annotation.Trace;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@ClientRegion("Customers")
|
||||
public interface CustomerRepository extends CrudRepository<Customer, Long> {
|
||||
|
||||
@@ -39,4 +42,4 @@ public interface CustomerRepository extends CrudRepository<Customer, Long> {
|
||||
@Limit(100)
|
||||
@Query("select * from /Customers customer where customer.firstName = $1")
|
||||
List<Customer> findByFirstNameUsingIndex(String firstName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
import example.springdata.geode.client.function.Order;
|
||||
import example.springdata.geode.client.function.Product;
|
||||
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
@@ -35,11 +36,11 @@ import org.springframework.data.gemfire.transaction.config.EnableGemfireCacheTra
|
||||
* @author Udo Kohlmeyer
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@EnableGemfireRepositories(basePackageClasses = CustomerRepository.class)
|
||||
@EnableGemfireFunctionExecutions(basePackageClasses = CustomerFunctionExecutions.class)
|
||||
@ClientCacheApplication(name = "FunctionInvocationClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1)
|
||||
@ClientCacheApplication(name = "FunctionInvocationClient", logLevel = "error", pingInterval = 5000L,
|
||||
readTimeout = 15000, retryAttempts = 1)
|
||||
@EnableGemfireCacheTransactions
|
||||
public class FunctionInvocationClientApplicationConfig {
|
||||
|
||||
@@ -69,4 +70,4 @@ public class FunctionInvocationClientApplicationConfig {
|
||||
clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
||||
return clientRegionFactoryBean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@OnRegion(region = "Orders")
|
||||
public interface OrderFunctionExecutions {
|
||||
|
||||
@FunctionId("sumPricesForAllProductsForOrderFnc")
|
||||
List<BigDecimal> sumPricesForAllProductsForOrder(Long orderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import example.springdata.geode.client.function.Order;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@ClientRegion("Orders")
|
||||
public interface OrderRepository extends CrudRepository<Order, Long> {
|
||||
|
||||
}
|
||||
public interface OrderRepository extends CrudRepository<Order, Long> {}
|
||||
|
||||
@@ -13,18 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.FunctionId;
|
||||
import org.springframework.data.gemfire.function.annotation.OnRegion;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@OnRegion(region = "Products")
|
||||
public interface ProductFunctionExecutions {
|
||||
|
||||
@FunctionId("sumPricesForAllProductsFnc")
|
||||
List<BigDecimal> sumPricesForAllProducts();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import example.springdata.geode.client.function.Product;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@ClientRegion("Products")
|
||||
public interface ProductRepository extends CrudRepository<Product, Long> {
|
||||
|
||||
}
|
||||
public interface ProductRepository extends CrudRepository<Product, Long> {}
|
||||
|
||||
@@ -13,25 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.server;
|
||||
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Component
|
||||
public class CustomerFunctions {
|
||||
|
||||
@GemfireFunction(id = "listConsumersForEmailAddressesFnc", HA = true, optimizeForWrite = true, batchSize = 3, hasResult = true)
|
||||
@GemfireFunction(id = "listConsumersForEmailAddressesFnc", HA = true, optimizeForWrite = true, batchSize = 3,
|
||||
hasResult = true)
|
||||
public List<Customer> listAllCustomersForEmailAddress(@RegionData Map<Long, Customer> customerData,
|
||||
String... emailAddresses) {
|
||||
String... emailAddresses) {
|
||||
List<String> emailAddressesAsList = Arrays.asList(emailAddresses);
|
||||
List<Customer> collect = customerData.values().parallelStream()
|
||||
.filter((customer) -> emailAddressesAsList.contains(customer.getEmailAddress().getValue()))
|
||||
|
||||
@@ -13,14 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.server;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = FunctionServerApplicationConfig.class)
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class FunctionServer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -13,16 +13,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.server;
|
||||
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
import example.springdata.geode.client.function.Order;
|
||||
import example.springdata.geode.client.function.Product;
|
||||
import example.springdata.geode.client.function.client.CustomerRepository;
|
||||
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.Scope;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -34,6 +35,9 @@ import org.springframework.data.gemfire.config.annotation.EnableManager;
|
||||
import org.springframework.data.gemfire.function.config.EnableGemfireFunctions;
|
||||
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = CustomerFunctions.class)
|
||||
@EnableGemfireFunctions
|
||||
|
||||
@@ -13,17 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.server;
|
||||
|
||||
import example.springdata.geode.client.function.Order;
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Component
|
||||
public class OrderFunctions {
|
||||
|
||||
|
||||
@@ -13,21 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.server;
|
||||
|
||||
import example.springdata.geode.client.function.Product;
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
|
||||
import org.springframework.data.gemfire.function.annotation.RegionData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Component
|
||||
public class ProductFunctions {
|
||||
|
||||
@GemfireFunction(id = "sumPricesForAllProductsFnc", HA = true, optimizeForWrite = false, hasResult = true)
|
||||
@GemfireFunction(id = "sumPricesForAllProductsFnc", HA = true, hasResult = true)
|
||||
public BigDecimal sumPricesForAllProductsFnc(@RegionData Map<Long, Product> productData) {
|
||||
return productData.values().stream().map(Product::getPrice).reduce(BigDecimal::add).get();
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.client.function.client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.geode.client.function.Address;
|
||||
import example.springdata.geode.client.function.Customer;
|
||||
import example.springdata.geode.client.function.EmailAddress;
|
||||
@@ -23,19 +24,8 @@ import example.springdata.geode.client.function.LineItem;
|
||||
import example.springdata.geode.client.function.Order;
|
||||
import example.springdata.geode.client.function.Product;
|
||||
import example.springdata.geode.client.function.server.FunctionServer;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@@ -43,41 +33,43 @@ import java.util.Random;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = FunctionInvocationClientApplicationConfig.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
@SpringBootTest(classes = FunctionInvocationClientApplicationConfig.class)
|
||||
@CommonsLog
|
||||
public class FunctionInvocationClientTests extends ForkingClientServerIntegrationTestsSupport {
|
||||
|
||||
@Autowired
|
||||
private CustomerRepository customerRepository;
|
||||
@Autowired private CustomerRepository customerRepository;
|
||||
|
||||
@Autowired
|
||||
private OrderRepository orderRepository;
|
||||
@Autowired private OrderRepository orderRepository;
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
@Autowired private ProductRepository productRepository;
|
||||
|
||||
@Autowired
|
||||
private CustomerFunctionExecutions customerFunctionExecutions;
|
||||
@Autowired private CustomerFunctionExecutions customerFunctionExecutions;
|
||||
|
||||
@Autowired
|
||||
private OrderFunctionExecutions orderFunctionExecutions;
|
||||
@Autowired private OrderFunctionExecutions orderFunctionExecutions;
|
||||
|
||||
@Autowired
|
||||
private ProductFunctionExecutions productFunctionExecutions;
|
||||
@Autowired private ProductFunctionExecutions productFunctionExecutions;
|
||||
|
||||
@Resource(name = "Customers")
|
||||
private Region<Long, Customer> customers;
|
||||
@Resource(name = "Customers") private Region<Long, Customer> customers;
|
||||
|
||||
@Resource(name = "Orders")
|
||||
private Region<Long, Order> orders;
|
||||
@Resource(name = "Orders") private Region<Long, Order> orders;
|
||||
|
||||
@Resource(name = "Products")
|
||||
private Region<Long, Product> products;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Resource(name = "Products") private Region<Long, Product> products;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
@@ -90,56 +82,60 @@ public class FunctionInvocationClientTests extends ForkingClientServerIntegratio
|
||||
|
||||
List<Customer> cust = customerFunctionExecutions.listAllCustomersForEmailAddress("2@2.com", "3@3.com").get(0);
|
||||
assertThat(cust.size()).isEqualTo(2);
|
||||
logger.info("All customers for emailAddresses:3@3.com,2@2.com using function invocation: \n\t " + cust);
|
||||
log.info("All customers for emailAddresses:3@3.com,2@2.com using function invocation: \n\t " + cust);
|
||||
|
||||
createProducts();
|
||||
BigDecimal sum = productFunctionExecutions.sumPricesForAllProducts().get(0);
|
||||
assertThat(sum).isEqualTo(BigDecimal.valueOf(1499.97));
|
||||
logger.info("Running function to sum up all product prices: \n\t" + sum);
|
||||
log.info("Running function to sum up all product prices: \n\t" + sum);
|
||||
|
||||
createOrders();
|
||||
|
||||
sum = orderFunctionExecutions.sumPricesForAllProductsForOrder(1L).get(0);
|
||||
assertThat(sum).isGreaterThanOrEqualTo(BigDecimal.valueOf(99.99));
|
||||
logger.info("Running function to sum up all order lineItems prices for order 1: \n\t" + sum);
|
||||
log.info("Running function to sum up all order lineItems prices for order 1: \n\t" + sum);
|
||||
Order order = orderRepository.findById(1L).get();
|
||||
logger.info("For order: \n\t " + order);
|
||||
log.info("For order: \n\t " + order);
|
||||
}
|
||||
|
||||
public void createCustomerData() {
|
||||
|
||||
logger.info("Inserting 3 entries for keys: 1, 2, 3");
|
||||
log.info("Inserting 3 entries for keys: 1, 2, 3");
|
||||
|
||||
customerRepository.save(new Customer(1L, new EmailAddress("2@2.com"), "John", "Smith"));
|
||||
customerRepository.save(new Customer(2L, new EmailAddress("3@3.com"), "Frank", "Lamport"));
|
||||
customerRepository.save(new Customer(3L, new EmailAddress("5@5.com"), "Jude", "Simmons"));
|
||||
|
||||
assertThat(customers.keySetOnServer().size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
public void createProducts() {
|
||||
productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"),
|
||||
"An Apple portable music player"));
|
||||
productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"),
|
||||
"An Apple tablet device"));
|
||||
Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"),
|
||||
"An Apple notebook computer");
|
||||
|
||||
productRepository.save(new Product(1L, "Apple iPod", new BigDecimal("99.99"), "An Apple portable music player"));
|
||||
productRepository.save(new Product(2L, "Apple iPad", new BigDecimal("499.99"), "An Apple tablet device"));
|
||||
Product macbook = new Product(3L, "Apple macBook", new BigDecimal("899.99"), "An Apple notebook computer");
|
||||
macbook.addAttribute("warranty", "included");
|
||||
|
||||
productRepository.save(macbook);
|
||||
|
||||
assertThat(products.keySetOnServer().size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
public void createOrders() {
|
||||
|
||||
Random random = new Random();
|
||||
Address address = new Address("it", "doesn't", "matter");
|
||||
LongStream.rangeClosed(1, 100).forEach((orderId) ->
|
||||
LongStream.rangeClosed(1, 3).forEach((customerId) -> {
|
||||
Order order = new Order(orderId, customerId, address);
|
||||
IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> {
|
||||
int quantity = random.nextInt(3) + 1;
|
||||
long productId = random.nextInt(3) + 1;
|
||||
order.add(new LineItem(productRepository.findById(productId).get(), quantity));
|
||||
});
|
||||
orderRepository.save(order);
|
||||
}));
|
||||
|
||||
LongStream.rangeClosed(1, 100).forEach((orderId) -> LongStream.rangeClosed(1, 3).forEach((customerId) -> {
|
||||
Order order = new Order(orderId, customerId, address);
|
||||
IntStream.rangeClosed(0, random.nextInt(3) + 1).forEach((lineItemCount) -> {
|
||||
int quantity = random.nextInt(3) + 1;
|
||||
long productId = random.nextInt(3) + 1;
|
||||
order.add(new LineItem(productRepository.findById(productId).get(), quantity));
|
||||
});
|
||||
orderRepository.save(order);
|
||||
}));
|
||||
|
||||
assertThat(orders.keySetOnServer().size()).isEqualTo(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user