use of org.apache.geode.cache.wan.GatewayTransportFilter in project geode by apache.
the class SerialGatewaySenderQueueDUnitTest method test_ValidateSerialGatewaySenderQueueAttributes_1.
/**
* Test to validate that serial gateway sender queue diskSynchronous attribute when persistence of
* sender is enabled.
*/
@Test
public void test_ValidateSerialGatewaySenderQueueAttributes_1() {
Integer localLocPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
Integer remoteLocPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, localLocPort));
WANTestBase test = new WANTestBase(getTestMethodName());
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + localLocPort + "]");
InternalDistributedSystem ds = test.getSystem(props);
cache = CacheFactory.create(ds);
File directory = new File("TKSender" + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
directory.mkdir();
File[] dirs1 = new File[] { directory };
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(dirs1);
DiskStore diskStore = dsf.create("FORNY");
GatewaySenderFactory fact = cache.createGatewaySenderFactory();
fact.setBatchConflationEnabled(true);
fact.setBatchSize(200);
fact.setBatchTimeInterval(300);
// enable the persistence
fact.setPersistenceEnabled(true);
fact.setDiskSynchronous(true);
fact.setDiskStoreName("FORNY");
fact.setMaximumQueueMemory(200);
fact.setAlertThreshold(1200);
GatewayEventFilter myEventFilter1 = new MyGatewayEventFilter1();
fact.addGatewayEventFilter(myEventFilter1);
GatewayTransportFilter myStreamFilter1 = new MyGatewayTransportFilter1();
fact.addGatewayTransportFilter(myStreamFilter1);
GatewayTransportFilter myStreamFilter2 = new MyGatewayTransportFilter2();
fact.addGatewayTransportFilter(myStreamFilter2);
final IgnoredException exTKSender = IgnoredException.addIgnoredException("Could not connect");
try {
GatewaySender sender1 = fact.create("TKSender", 2);
AttributesFactory factory = new AttributesFactory();
factory.addGatewaySenderId(sender1.getId());
factory.setDataPolicy(DataPolicy.PARTITION);
Region region = cache.createRegionFactory(factory.create()).create("test_ValidateGatewaySenderAttributes");
Set<GatewaySender> senders = cache.getGatewaySenders();
assertEquals(senders.size(), 1);
GatewaySender gatewaySender = senders.iterator().next();
Set<RegionQueue> regionQueues = ((AbstractGatewaySender) gatewaySender).getQueues();
assertEquals(regionQueues.size(), GatewaySender.DEFAULT_DISPATCHER_THREADS);
RegionQueue regionQueue = regionQueues.iterator().next();
assertEquals(true, regionQueue.getRegion().getAttributes().isDiskSynchronous());
} finally {
exTKSender.remove();
}
}
use of org.apache.geode.cache.wan.GatewayTransportFilter in project geode by apache.
the class SerialGatewaySenderQueueDUnitTest method test_ValidateSerialGatewaySenderQueueAttributes_2.
/**
* Test to validate that serial gateway sender queue diskSynchronous attribute when persistence of
* sender is not enabled.
*/
@Test
public void test_ValidateSerialGatewaySenderQueueAttributes_2() {
Integer localLocPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
Integer remoteLocPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, localLocPort));
WANTestBase test = new WANTestBase(getTestMethodName());
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + localLocPort + "]");
InternalDistributedSystem ds = test.getSystem(props);
cache = CacheFactory.create(ds);
GatewaySenderFactory fact = cache.createGatewaySenderFactory();
fact.setBatchConflationEnabled(true);
fact.setBatchSize(200);
fact.setBatchTimeInterval(300);
// set persistence to false
fact.setPersistenceEnabled(false);
fact.setDiskSynchronous(true);
fact.setMaximumQueueMemory(200);
fact.setAlertThreshold(1200);
GatewayEventFilter myEventFilter1 = new MyGatewayEventFilter1();
fact.addGatewayEventFilter(myEventFilter1);
GatewayTransportFilter myStreamFilter1 = new MyGatewayTransportFilter1();
fact.addGatewayTransportFilter(myStreamFilter1);
GatewayTransportFilter myStreamFilter2 = new MyGatewayTransportFilter2();
fact.addGatewayTransportFilter(myStreamFilter2);
final IgnoredException exp = IgnoredException.addIgnoredException("Could not connect");
try {
GatewaySender sender1 = fact.create("TKSender", 2);
AttributesFactory factory = new AttributesFactory();
factory.addGatewaySenderId(sender1.getId());
factory.setDataPolicy(DataPolicy.PARTITION);
Region region = cache.createRegionFactory(factory.create()).create("test_ValidateGatewaySenderAttributes");
Set<GatewaySender> senders = cache.getGatewaySenders();
assertEquals(senders.size(), 1);
GatewaySender gatewaySender = senders.iterator().next();
Set<RegionQueue> regionQueues = ((AbstractGatewaySender) gatewaySender).getQueues();
assertEquals(regionQueues.size(), GatewaySender.DEFAULT_DISPATCHER_THREADS);
RegionQueue regionQueue = regionQueues.iterator().next();
assertEquals(false, regionQueue.getRegion().getAttributes().isDiskSynchronous());
} finally {
exp.remove();
}
}
use of org.apache.geode.cache.wan.GatewayTransportFilter in project geode by apache.
the class CacheXmlGenerator method generateGatewayReceiver.
private void generateGatewayReceiver(Cache cache) throws SAXException {
Set<GatewayReceiver> receiverList = cache.getGatewayReceivers();
for (GatewayReceiver receiver : receiverList) {
AttributesImpl atts = new AttributesImpl();
try {
// start port
if (generateDefaults() || receiver.getStartPort() != GatewayReceiver.DEFAULT_START_PORT)
atts.addAttribute("", "", START_PORT, "", String.valueOf(receiver.getStartPort()));
// end port
if (generateDefaults() || receiver.getEndPort() != GatewayReceiver.DEFAULT_END_PORT)
atts.addAttribute("", "", END_PORT, "", String.valueOf(receiver.getEndPort()));
// bind-address
if (generateDefaults() || (receiver.getBindAddress() != null && !receiver.getBindAddress().equals(GatewayReceiver.DEFAULT_BIND_ADDRESS)))
atts.addAttribute("", "", BIND_ADDRESS, "", receiver.getBindAddress());
// maximum-time-between-pings
if (generateDefaults() || receiver.getMaximumTimeBetweenPings() != GatewayReceiver.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS)
atts.addAttribute("", "", MAXIMUM_TIME_BETWEEN_PINGS, "", String.valueOf(receiver.getMaximumTimeBetweenPings()));
// socket-buffer-size
if (generateDefaults() || receiver.getSocketBufferSize() != GatewayReceiver.DEFAULT_SOCKET_BUFFER_SIZE)
atts.addAttribute("", "", SOCKET_BUFFER_SIZE, "", String.valueOf(receiver.getSocketBufferSize()));
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) {
return;
}
// manual-start
if (generateDefaults() || receiver.isManualStart() != GatewayReceiver.DEFAULT_MANUAL_START)
atts.addAttribute("", "", MANUAL_START, "", String.valueOf(receiver.isManualStart()));
} finally {
handler.startElement("", GATEWAY_RECEIVER, GATEWAY_RECEIVER, atts);
for (GatewayTransportFilter gsf : receiver.getGatewayTransportFilters()) {
generateGatewayTransportFilter(gsf);
}
handler.endElement("", GATEWAY_RECEIVER, GATEWAY_RECEIVER);
}
}
}
use of org.apache.geode.cache.wan.GatewayTransportFilter in project geode by apache.
the class GatewaySenderMBeanBridge method getGatewayTransportFilters.
public String[] getGatewayTransportFilters() {
List<GatewayTransportFilter> transportFilters = sender.getGatewayTransportFilters();
String[] transportFiltersStr = null;
if (transportFilters != null && transportFilters.size() > 0) {
transportFiltersStr = new String[transportFilters.size()];
} else {
return transportFiltersStr;
}
int j = 0;
for (GatewayTransportFilter listener : transportFilters) {
transportFiltersStr[j] = listener.getClass().getCanonicalName();
j++;
}
return transportFiltersStr;
}
use of org.apache.geode.cache.wan.GatewayTransportFilter in project geode by apache.
the class GatewaySenderAdvisor method checkCompatibility.
private void checkCompatibility(GatewaySenderProfile sp) {
if (sp.remoteDSId != sender.getRemoteDSId()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_REMOTE_DS_ID_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_2_REMOTE_DS_ID.toString(new Object[] { sp.Id, sp.remoteDSId, sender.remoteDSId }));
}
if (sp.isParallel && !sender.isParallel()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_AS_PARALLEL_GATEWAY_SENDER_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_AS_SERIAL_GATEWAY_SENDER.toString(new Object[] { sp.Id }));
}
if (!sp.isParallel && sender.isParallel()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_AS_SERIAL_GATEWAY_SENDER_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_AS_PARALLEL_GATEWAY_SENDER.toString(new Object[] { sp.Id }));
}
if (sp.isBatchConflationEnabled != sender.isBatchConflationEnabled()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_IS_BACTH_CONFLATION_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_IS_BATCH_CONFLATION_2.toString(new Object[] { sp.Id, sp.isBatchConflationEnabled, sender.isBatchConflationEnabled() }));
}
if (sp.isPersistenceEnabled != sender.isPersistenceEnabled()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_IS_PERSISTENT_ENABLED_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_IS_PERSISTENT_ENABLED_2.toString(new Object[] { sp.Id, sp.isPersistenceEnabled, sender.isPersistenceEnabled() }));
}
if (sp.alertThreshold != sender.getAlertThreshold()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_ALERT_THRESHOLD_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_ALERT_THRESHOLD_2.toString(new Object[] { sp.Id, sp.alertThreshold, sender.getAlertThreshold() }));
}
if (!sender.isParallel()) {
if (sp.manualStart != sender.isManualStart()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_MANUAL_START_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_MANUAL_START_2.toString(new Object[] { sp.Id, sp.manualStart, sender.isManualStart() }));
}
}
if (!sp.isParallel) {
if (sp.orderPolicy != sender.getOrderPolicy()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_ORDER_POLICY_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_ORDER_POLICY_2.toString(new Object[] { sp.Id, sp.orderPolicy, sender.getOrderPolicy() }));
}
}
List<String> senderEventFilterClassNames = new ArrayList<String>();
for (org.apache.geode.cache.wan.GatewayEventFilter filter : sender.getGatewayEventFilters()) {
senderEventFilterClassNames.add(filter.getClass().getName());
}
if (sp.eventFiltersClassNames.size() != senderEventFilterClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_EVENT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.eventFiltersClassNames, senderEventFilterClassNames }));
} else {
for (String filterName : senderEventFilterClassNames) {
if (!sp.eventFiltersClassNames.contains(filterName)) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_EVENT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.eventFiltersClassNames, senderEventFilterClassNames }));
}
}
}
Set<String> senderTransportFilterClassNames = new LinkedHashSet<String>();
for (GatewayTransportFilter filter : sender.getGatewayTransportFilters()) {
senderTransportFilterClassNames.add(filter.getClass().getName());
}
if (sp.transFiltersClassNames.size() != senderTransportFilterClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_TRANSPORT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.transFiltersClassNames, senderTransportFilterClassNames }));
} else {
Iterator<String> i1 = sp.transFiltersClassNames.iterator();
Iterator<String> i2 = senderTransportFilterClassNames.iterator();
while (i1.hasNext() && i2.hasNext()) {
if (!i1.next().equals(i2.next())) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_TRANSPORT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.transFiltersClassNames, senderTransportFilterClassNames }));
}
}
}
List<String> senderEventListenerClassNames = new ArrayList<String>();
for (AsyncEventListener listener : sender.getAsyncEventListeners()) {
senderEventListenerClassNames.add(listener.getClass().getName());
}
if (sp.senderEventListenerClassNames.size() != senderEventListenerClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_LISTENER_MISMATCH.toString(new Object[] { sp.Id, sp.senderEventListenerClassNames, senderEventListenerClassNames }));
} else {
for (String listenerName : senderEventListenerClassNames) {
if (!sp.senderEventListenerClassNames.contains(listenerName)) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_LISTENER_MISMATCH.toString(new Object[] { sp.Id, sp.senderEventListenerClassNames, senderEventListenerClassNames }));
}
}
}
if (sp.isDiskSynchronous != sender.isDiskSynchronous()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_IS_DISK_SYNCHRONOUS_MISMATCH.toString(new Object[] { sp.Id, sp.isDiskSynchronous, sender.isDiskSynchronous() }));
}
}
Aggregations