JAVA-1848: Moved apache-geode to apache-libraries
This commit is contained in:
parent
b192e90444
commit
06d2080523
@ -1,7 +0,0 @@
|
|||||||
## Apache Geode
|
|
||||||
|
|
||||||
This module contains articles about Apache Geode
|
|
||||||
|
|
||||||
### Relevant Articles:
|
|
||||||
|
|
||||||
- [A Quick Guide to Apache Geode](https://www.baeldung.com/apache-geode)
|
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<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>
|
|
||||||
<artifactId>apache-geode</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<name>apache-geode</name>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.geode</groupId>
|
|
||||||
<artifactId>geode-core</artifactId>
|
|
||||||
<version>${geode.core}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<geode.core>1.6.0</geode.core>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,78 +0,0 @@
|
|||||||
package com.baeldung.geode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Customer implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -7482516011038799900L;
|
|
||||||
|
|
||||||
private CustomerKey key;
|
|
||||||
private String firstName;
|
|
||||||
private String lastName;
|
|
||||||
private Integer age;
|
|
||||||
|
|
||||||
public Customer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Customer(String firstName, String lastName, int age) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.lastName = lastName;
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Customer(CustomerKey key, String firstName, String lastName, int age) {
|
|
||||||
this(firstName, lastName, age);
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
// setters and getters
|
|
||||||
|
|
||||||
public static long getSerialVersionUID() {
|
|
||||||
return serialVersionUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Integer getAge() {
|
|
||||||
return age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAge(Integer age) {
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Customer{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", age=" + age + '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o)
|
|
||||||
return true;
|
|
||||||
if (o == null || getClass() != o.getClass())
|
|
||||||
return false;
|
|
||||||
Customer customer = (Customer) o;
|
|
||||||
return Objects.equals(firstName, customer.firstName) && Objects.equals(lastName, customer.lastName) && Objects.equals(age, customer.age);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(firstName, lastName, age);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
package com.baeldung.geode;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class CustomerKey implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3529253035303792458L;
|
|
||||||
private long id;
|
|
||||||
private String country;
|
|
||||||
|
|
||||||
public CustomerKey(long id) {
|
|
||||||
this.id = id;
|
|
||||||
this.country = "USA";
|
|
||||||
}
|
|
||||||
|
|
||||||
public CustomerKey(long id, String country) {
|
|
||||||
this.id = id;
|
|
||||||
this.country = country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountry() {
|
|
||||||
return country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountry(String country) {
|
|
||||||
this.country = country;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o)
|
|
||||||
return true;
|
|
||||||
if (o == null || getClass() != o.getClass())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CustomerKey that = (CustomerKey) o;
|
|
||||||
|
|
||||||
if (id != that.id)
|
|
||||||
return false;
|
|
||||||
return country != null ? country.equals(that.country) : that.country == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = (int) (id ^ (id >>> 32));
|
|
||||||
result = 31 * result + (country != null ? country.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package com.baeldung.geode.functions;
|
|
||||||
|
|
||||||
import com.baeldung.geode.Customer;
|
|
||||||
import com.baeldung.geode.CustomerKey;
|
|
||||||
import org.apache.geode.cache.Region;
|
|
||||||
import org.apache.geode.cache.execute.Function;
|
|
||||||
import org.apache.geode.cache.execute.FunctionContext;
|
|
||||||
import org.apache.geode.cache.execute.RegionFunctionContext;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class UpperCaseNames implements Function<Boolean> {
|
|
||||||
private static final long serialVersionUID = -8946294032165677602L;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(FunctionContext<Boolean> context) {
|
|
||||||
RegionFunctionContext regionContext = (RegionFunctionContext) context;
|
|
||||||
Region<CustomerKey, Customer> region = regionContext.getDataSet();
|
|
||||||
|
|
||||||
for (Map.Entry<CustomerKey, Customer> entry : region.entrySet()) {
|
|
||||||
Customer customer = entry.getValue();
|
|
||||||
customer.setFirstName(customer.getFirstName()
|
|
||||||
.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
context.getResultSender()
|
|
||||||
.lastResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return getClass().getName();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
package com.baeldung.geode;
|
|
||||||
|
|
||||||
import com.baeldung.geode.functions.UpperCaseNames;
|
|
||||||
import org.apache.geode.cache.Region;
|
|
||||||
import org.apache.geode.cache.client.ClientCache;
|
|
||||||
import org.apache.geode.cache.client.ClientCacheFactory;
|
|
||||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
|
||||||
import org.apache.geode.cache.execute.Execution;
|
|
||||||
import org.apache.geode.cache.execute.FunctionService;
|
|
||||||
import org.apache.geode.cache.query.*;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class GeodeSamplesLiveTest {
|
|
||||||
|
|
||||||
ClientCache cache = null;
|
|
||||||
Region<String, String> region = null;
|
|
||||||
Region<Integer, Customer> queryRegion = null;
|
|
||||||
Region<CustomerKey, Customer> customerRegion = null;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void connect() {
|
|
||||||
this.cache = new ClientCacheFactory().addPoolLocator("localhost", 10334)
|
|
||||||
.create();
|
|
||||||
this.region = this.cache.<String, String> createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
|
|
||||||
.create("baeldung");
|
|
||||||
this.customerRegion = this.cache.<CustomerKey, Customer> createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
|
|
||||||
.create("baeldung-customers");
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void cleanup() {
|
|
||||||
this.cache.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenSendMessageToRegion_thenMessageSavedSuccessfully() {
|
|
||||||
|
|
||||||
this.region.put("1", "Hello");
|
|
||||||
this.region.put("2", "Baeldung");
|
|
||||||
|
|
||||||
assertEquals("Hello", region.get("1"));
|
|
||||||
assertEquals("Baeldung", region.get("2"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenPutMultipleValuesAtOnce_thenValuesSavedSuccessfully() {
|
|
||||||
|
|
||||||
Supplier<Stream<String>> keys = () -> Stream.of("A", "B", "C", "D", "E");
|
|
||||||
Map<String, String> values = keys.get()
|
|
||||||
.collect(Collectors.toMap(Function.identity(), String::toLowerCase));
|
|
||||||
|
|
||||||
this.region.putAll(values);
|
|
||||||
|
|
||||||
keys.get()
|
|
||||||
.forEach(k -> assertEquals(k.toLowerCase(), this.region.get(k)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenPutCustomKey_thenValuesSavedSuccessfully() {
|
|
||||||
CustomerKey key = new CustomerKey(123);
|
|
||||||
Customer customer = new Customer(key, "William", "Russell", 35);
|
|
||||||
|
|
||||||
Map<CustomerKey, Customer> customerInfo = new HashMap<>();
|
|
||||||
customerInfo.put(key, customer);
|
|
||||||
|
|
||||||
this.customerRegion.putAll(customerInfo);
|
|
||||||
|
|
||||||
Customer storedCustomer = this.customerRegion.get(key);
|
|
||||||
assertEquals("William", storedCustomer.getFirstName());
|
|
||||||
assertEquals("Russell", storedCustomer.getLastName());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenFindACustomerUsingOQL_thenCorrectCustomerObject() throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException {
|
|
||||||
|
|
||||||
Map<CustomerKey, Customer> data = new HashMap<>();
|
|
||||||
data.put(new CustomerKey(1), new Customer("Gheorge", "Manuc", 36));
|
|
||||||
data.put(new CustomerKey(2), new Customer("Allan", "McDowell", 43));
|
|
||||||
this.customerRegion.putAll(data);
|
|
||||||
|
|
||||||
QueryService queryService = this.cache.getQueryService();
|
|
||||||
String query = "select * from /baeldung-customers c where c.firstName = 'Allan'";
|
|
||||||
SelectResults<Customer> queryResults = (SelectResults<Customer>) queryService.newQuery(query)
|
|
||||||
.execute();
|
|
||||||
assertEquals(1, queryResults.size());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenExecuteUppercaseNames_thenCustomerNamesAreUppercased() {
|
|
||||||
Execution execution = FunctionService.onRegion(this.customerRegion);
|
|
||||||
execution.execute(UpperCaseNames.class.getName());
|
|
||||||
Customer customer = this.customerRegion.get(new CustomerKey(1));
|
|
||||||
assertEquals("GHEORGE", customer.getFirstName());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user