@@ -0,0 +1,2987 @@
+/*%0A *      Copyright (C) 2012-2015 DataStax Inc.%0A *%0A *   Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *   you may not use this file except in compliance with the License.%0A *   You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *   Unless required by applicable law or agreed to in writing, software%0A *   distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *   See the License for the specific language governing permissions and%0A *   limitations under the License.%0A */%0Apackage com.datastax.driver.core;%0A%0Aimport java.util.Collection;%0A%0Aimport com.google.common.collect.Lists;%0Aimport org.mockito.Mockito;%0Aimport org.testng.annotations.Test;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.mockito.Mockito.times;%0A%0Aimport com.datastax.driver.core.policies.ConstantSpeculativeExecutionPolicy;%0Aimport com.datastax.driver.core.utils.CassandraVersion;%0A%0A/**%0A * Test that needs a real CCM cluster (as opposed to SCassandra for other specex tests), because%0A * it uses a protocol v3 feature.%0A */%0Apublic class SpeculativeExecutionIntegrationTest extends CCMBridge.PerClassSingleNodeCluster %7B%0A%0A    TimestampGenerator timestampGenerator;%0A%0A    @Override%0A    protected Collection%3CString%3E getTableDefinitions() %7B%0A        return Lists.newArrayList(%22create table foo(k int primary key, v int)%22);%0A    %7D%0A%0A    @Override%0A    protected Cluster.Builder configure(Cluster.Builder builder) %7B%0A        timestampGenerator = Mockito.spy(ServerSideTimestampGenerator.INSTANCE);%0A        return builder%0A            .withTimestampGenerator(timestampGenerator)%0A            .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))%0A                // Set an artificially low timeout to force speculative execution%0A            .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(1, 2));%0A    %7D%0A%0A    /**%0A     * Validates that if a query gets speculatively re-executed, the second execution uses the same default timestamp.%0A     *%0A     * @test_category tracing%0A     * @jira_ticket JAVA-724%0A     * @expected_result timestamp generator invoked only once for a query that caused two executions.%0A     */%0A    @Test(groups = %22short%22)%0A    @CassandraVersion(major = 2.1)%0A    public void should_use_same_default_timestamp_for_all_executions() %7B%0A        Metrics.Errors errors = cluster.getMetrics().getErrorMetrics();%0A%0A        Mockito.reset(timestampGenerator);%0A        long execStartCount = errors.getSpeculativeExecutions().getCount();%0A%0A        BatchStatement batch = new BatchStatement();%0A        for (int k = 0; k %3C 1000; k++) %7B%0A            batch.add(new SimpleStatement(%22insert into foo(k,v) values (?,1)%22, k));%0A        %7D%0A        session.execute(batch);%0A%0A        assertThat(errors.getSpeculativeExecutions().getCount()).isEqualTo(execStartCount + 1);%0A        Mockito.verify(timestampGenerator, times(1)).next();%0A    %7D%0A%7D%0A

Test that speculative executions use the same timestamp (JAVA-724).