Skip to content

Commit

Permalink
GEODE-7530: returns localSize on ParallelGatewaySenderQueue (apache#4424
Browse files Browse the repository at this point in the history
)

 * returns localSize on ParallelGatewaySenderQueue for eventQueueSize.
  • Loading branch information
pivotal-eshu authored Dec 6, 2019
1 parent e3a31e1 commit 49eefca
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,7 @@ protected Object eventQueueTake() throws CacheException, InterruptedException {
}

public int eventQueueSize() {
if (queue == null) {
return 0;
}

// This should be local size instead of pr size
if (this.queue instanceof ConcurrentParallelGatewaySenderQueue) {
return ((ConcurrentParallelGatewaySenderQueue) queue).localSize();
}
return this.queue.size();
return getQueue() == null ? 0 : getQueue().size();
}

public int secondaryEventQueueSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ protected void initializeMessageQueue(String id) {
// nothing
}

@Override
public int eventQueueSize() {
ConcurrentParallelGatewaySenderQueue queue = (ConcurrentParallelGatewaySenderQueue) getQueue();
return queue == null ? 0 : queue.localSize();
}

@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue)
throws IOException, CacheException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ protected void initializeMessageQueue(String id) {
}
}

@Override
public int eventQueueSize() {
ParallelGatewaySenderQueue queue = (ParallelGatewaySenderQueue) getQueue();
return queue == null ? 0 : queue.localSize();
}

@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue)
throws IOException, CacheException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache.wan;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Test;

import org.apache.geode.internal.cache.RegionQueue;

public class AbstractGatewaySenderEventProcessorTest {

private RegionQueue queue = mock(RegionQueue.class);

@Test
public void eventQueueSizeReturnsQueueSize() {
AbstractGatewaySenderEventProcessor processor = mock(AbstractGatewaySenderEventProcessor.class);
when(processor.getQueue()).thenReturn(queue);
doCallRealMethod().when(processor).eventQueueSize();

processor.eventQueueSize();

verify(queue).size();
}

@Test
public void eventQueueSizeReturnsZeroIfRegionQueueIsNull() {
AbstractGatewaySenderEventProcessor processor = mock(AbstractGatewaySenderEventProcessor.class);
doCallRealMethod().when(processor).eventQueueSize();

assertThat(processor.eventQueueSize()).isEqualTo(0);

verify(queue, never()).size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache.wan.parallel;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;

import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
import org.apache.geode.internal.monitoring.ThreadsMonitoring;

public class ConcurrentParallelGatewaySenderEventProcessorTest {
private AbstractGatewaySender sender = mock(AbstractGatewaySender.class);
private ConcurrentParallelGatewaySenderQueue queue =
mock(ConcurrentParallelGatewaySenderQueue.class);

@Before
public void setup() {
when(sender.getCache()).thenReturn(mock(InternalCache.class));
}

@Test
public void eventQueueSizeReturnsQueueLocalSize() {
ConcurrentParallelGatewaySenderEventProcessor processor =
spy(new ConcurrentParallelGatewaySenderEventProcessor(sender, mock(
ThreadsMonitoring.class)));
doReturn(queue).when(processor).getQueue();

processor.eventQueueSize();

verify(queue).localSize();
}

@Test
public void eventQueueSizeReturnsZeroIfQueueIsNull() {
ConcurrentParallelGatewaySenderEventProcessor processor =
spy(new ConcurrentParallelGatewaySenderEventProcessor(sender, mock(
ThreadsMonitoring.class)));
doReturn(null).when(processor).getQueue();

assertThat(processor.eventQueueSize()).isEqualTo(0);

verify(queue, never()).localSize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache.wan.parallel;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;

import org.apache.geode.CancelCriterion;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.wan.AbstractGatewaySender;
import org.apache.geode.internal.monitoring.ThreadsMonitoring;

public class ParallelGatewaySenderEventProcessorTest {

private AbstractGatewaySender sender = mock(AbstractGatewaySender.class);
private ParallelGatewaySenderQueue queue = mock(ParallelGatewaySenderQueue.class);

@Before
public void setup() {
when(sender.getCache()).thenReturn(mock(InternalCache.class));
when(sender.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
}

@Test
public void eventQueueSizeReturnsQueueLocalSize() {
ParallelGatewaySenderEventProcessor processor =
spy(new ParallelGatewaySenderEventProcessor(sender, mock(
ThreadsMonitoring.class)));
doReturn(queue).when(processor).getQueue();

processor.eventQueueSize();

verify(queue).localSize();
}

@Test
public void eventQueueSizeReturnsZeroIfQueueIsNull() {
ParallelGatewaySenderEventProcessor processor =
spy(new ParallelGatewaySenderEventProcessor(sender, mock(
ThreadsMonitoring.class)));
doReturn(null).when(processor).getQueue();

assertThat(processor.eventQueueSize()).isEqualTo(0);

verify(queue, never()).localSize();
}
}

0 comments on commit 49eefca

Please sign in to comment.