-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #1429
- Loading branch information
Showing
9 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ language: java | |
dist: xenial | ||
jdk: openjdk8 | ||
|
||
services: | ||
- docker | ||
|
||
env: | ||
- TRAVIS_NODE_VERSION="lts/*" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../de/codecentric/boot/admin/server/eventstore/HazelcastEventStoreWithClientConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2014-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package de.codecentric.boot.admin.server.eventstore; | ||
|
||
import java.util.List; | ||
|
||
import com.hazelcast.client.config.ClientConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.core.IMap; | ||
import org.springframework.boot.autoconfigure.hazelcast.HazelcastClientFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import de.codecentric.boot.admin.server.domain.events.InstanceEvent; | ||
import de.codecentric.boot.admin.server.domain.values.InstanceId; | ||
|
||
@Testcontainers | ||
public class HazelcastEventStoreWithClientConfigTest extends AbstractEventStoreTest { | ||
|
||
@Container | ||
private static GenericContainer hazelcastServer = new GenericContainer("hazelcast/hazelcast:3.12.8") | ||
.withExposedPorts(5701); | ||
|
||
private final HazelcastInstance hazelcast; | ||
|
||
public HazelcastEventStoreWithClientConfigTest() { | ||
this.hazelcast = createHazelcastInstance(); | ||
} | ||
|
||
@Override | ||
protected InstanceEventStore createStore(int maxLogSizePerAggregate) { | ||
IMap<InstanceId, List<InstanceEvent>> eventLog = hazelcast.getMap("testList" + System.currentTimeMillis()); | ||
return new HazelcastEventStore(maxLogSizePerAggregate, eventLog); | ||
} | ||
|
||
private HazelcastInstance createHazelcastInstance() { | ||
String address = hazelcastServer.getContainerIpAddress() + ":" + hazelcastServer.getMappedPort(5701); | ||
|
||
ClientConfig clientConfig = new ClientConfig(); | ||
clientConfig.getNetworkConfig().addAddress(address); | ||
|
||
return (new HazelcastClientFactory(clientConfig)).getHazelcastInstance(); | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
.../de/codecentric/boot/admin/server/eventstore/HazelcastEventStoreWithServerConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2014-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package de.codecentric.boot.admin.server.eventstore; | ||
|
||
import java.util.List; | ||
|
||
import com.hazelcast.config.Config; | ||
import com.hazelcast.config.EvictionPolicy; | ||
import com.hazelcast.config.InMemoryFormat; | ||
import com.hazelcast.config.MapConfig; | ||
import com.hazelcast.config.MergePolicyConfig; | ||
import com.hazelcast.config.TcpIpConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.core.IMap; | ||
import com.hazelcast.map.merge.PutIfAbsentMapMergePolicy; | ||
import org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory; | ||
|
||
import de.codecentric.boot.admin.server.domain.events.InstanceEvent; | ||
import de.codecentric.boot.admin.server.domain.values.InstanceId; | ||
|
||
import static de.codecentric.boot.admin.server.config.AdminServerHazelcastAutoConfiguration.DEFAULT_NAME_EVENT_STORE_MAP; | ||
import static de.codecentric.boot.admin.server.config.AdminServerHazelcastAutoConfiguration.DEFAULT_NAME_SENT_NOTIFICATIONS_MAP; | ||
import static java.util.Collections.singletonList; | ||
|
||
public class HazelcastEventStoreWithServerConfigTest extends AbstractEventStoreTest { | ||
|
||
private final HazelcastInstance hazelcast; | ||
|
||
public HazelcastEventStoreWithServerConfigTest() { | ||
this.hazelcast = createHazelcastInstance(); | ||
} | ||
|
||
@Override | ||
protected InstanceEventStore createStore(int maxLogSizePerAggregate) { | ||
IMap<InstanceId, List<InstanceEvent>> eventLogs = hazelcast.getMap("testList" + System.currentTimeMillis()); | ||
return new HazelcastEventStore(maxLogSizePerAggregate, eventLogs); | ||
} | ||
|
||
private HazelcastInstance createHazelcastInstance() { | ||
Config config = createHazelcastConfig(); | ||
return (new HazelcastInstanceFactory(config)).getHazelcastInstance(); | ||
} | ||
|
||
// config from sample project | ||
private Config createHazelcastConfig() { | ||
// This map is used to store the events. | ||
// It should be configured to reliably hold all the data, | ||
// Spring Boot Admin will compact the events, if there are too many | ||
MapConfig eventStoreMap = new MapConfig(DEFAULT_NAME_EVENT_STORE_MAP).setInMemoryFormat(InMemoryFormat.OBJECT) | ||
.setBackupCount(1).setEvictionPolicy(EvictionPolicy.NONE) | ||
.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); | ||
|
||
// This map is used to deduplicate the notifications. | ||
// If data in this map gets lost it should not be a big issue as it will atmost | ||
// lead to | ||
// the same notification to be sent by multiple instances | ||
MapConfig sentNotificationsMap = new MapConfig(DEFAULT_NAME_SENT_NOTIFICATIONS_MAP) | ||
.setInMemoryFormat(InMemoryFormat.OBJECT).setBackupCount(1).setEvictionPolicy(EvictionPolicy.LRU) | ||
.setMergePolicyConfig(new MergePolicyConfig(PutIfAbsentMapMergePolicy.class.getName(), 100)); | ||
|
||
Config config = new Config(); | ||
config.addMapConfig(eventStoreMap); | ||
config.addMapConfig(sentNotificationsMap); | ||
config.setProperty("hazelcast.jmx", "true"); | ||
|
||
// WARNING: This setups a local cluster, you change it to fit your needs. | ||
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); | ||
TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig(); | ||
tcpIpConfig.setEnabled(true); | ||
tcpIpConfig.setMembers(singletonList("127.0.0.1")); | ||
return config; | ||
} | ||
|
||
} |