DATAREDIS-1011 - Allow configuration of Lettuce pipelining flush behavior.
We now allow customization of flushing when using pipelining with Lettuce. Lettuce flushes each command by default. To optimize for performance, flushing behavior can be customized using a PipeliningFlushPolicy. Flush each command, flush on close and flush after n commands are the bundled implementations that can be configured on LettuceConnectionFactory. Original Pull Request: #511
This commit is contained in:
committed by
Christoph Strobl
parent
a918d83526
commit
42ad8d190d
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2011-2020 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnection} pipeline functionality with
|
||||
* {@link LettuceConnection.PipeliningFlushPolicy}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(RelaxedJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("LettuceConnectionPipelineFlushOnEndIntegrationTests-context.xml")
|
||||
public class LettuceConnectionPipelineFlushOnEndIntegrationTests extends LettuceConnectionPipelineIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Ignore("WATCH command is flushed during EXEC therefore we're not run commands between WATCH and EXEC")
|
||||
public void testWatch() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2013-2020 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration test of {@link LettuceConnection} transactions within a pipeline
|
||||
* {@link LettuceConnection.PipeliningFlushPolicy}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration("LettuceConnectionPipelineFlushOnEndIntegrationTests-context.xml")
|
||||
public class LettuceConnectionPipelineTxFlushOnEndIntegrationTests extends LettuceConnectionPipelineTxIntegrationTests {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2020 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
|
||||
*
|
||||
* https://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.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.redis.connection.lettuce.LettuceConnection.*;
|
||||
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PipeliningFlushPolicy}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PipeliningFlushPolicyUnitTests {
|
||||
|
||||
@Mock StatefulRedisConnection<?, ?> connection;
|
||||
|
||||
@Test // DATAREDIS-1011
|
||||
public void shouldFlushEachCommand() {
|
||||
|
||||
PipeliningFlushPolicy policy = PipeliningFlushPolicy.flushEachCommand();
|
||||
|
||||
PipeliningFlushState state = policy.newPipeline();
|
||||
|
||||
state.onOpen(connection);
|
||||
state.onCommand(connection);
|
||||
state.onClose(connection);
|
||||
|
||||
verifyNoInteractions(connection);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1011
|
||||
public void shouldFlushOnClose() {
|
||||
|
||||
PipeliningFlushPolicy policy = PipeliningFlushPolicy.flushOnClose();
|
||||
|
||||
PipeliningFlushState state = policy.newPipeline();
|
||||
|
||||
state.onOpen(connection);
|
||||
|
||||
verify(connection).setAutoFlushCommands(false);
|
||||
|
||||
state.onCommand(connection);
|
||||
|
||||
verifyNoMoreInteractions(connection);
|
||||
|
||||
state.onClose(connection);
|
||||
|
||||
verify(connection).setAutoFlushCommands(true);
|
||||
verify(connection).flushCommands();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1011
|
||||
public void shouldFlushOnBuffer() {
|
||||
|
||||
PipeliningFlushPolicy policy = PipeliningFlushPolicy.buffered(2);
|
||||
|
||||
PipeliningFlushState state = policy.newPipeline();
|
||||
|
||||
state.onOpen(connection);
|
||||
|
||||
verify(connection).setAutoFlushCommands(false);
|
||||
|
||||
state.onCommand(connection);
|
||||
verifyNoMoreInteractions(connection);
|
||||
|
||||
state.onCommand(connection);
|
||||
verify(connection).flushCommands();
|
||||
|
||||
state.onClose(connection);
|
||||
|
||||
verify(connection).setAutoFlushCommands(true);
|
||||
verify(connection, times(2)).flushCommands();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user