/*
 *      Copyright (C) 2012-2015 DataStax Inc.
 *
 *   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 com.datastax.driver.core;

import com.datastax.driver.core.utils.CassandraVersion;
import com.google.common.base.Strings;
import org.testng.annotations.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class WarningsTest extends CCMTestsSupport {

    /**
     * This is Cassandra's default value, found in o.a.c.config.Config
     */
    private static final int BATCH_SIZE_WARN_THRESHOLD_IN_BYTES = 5 * 1024;

    @Override
    public void onTestContextInitialized() {
        execute("CREATE TABLE foo(k int primary key, v text)");
    }

    @CassandraVersion(major = 2.2)
    @Test(groups = "short")
    public void should_expose_warnings_on_execution_info() {
        ResultSet rs = session().execute(String.format("BEGIN UNLOGGED BATCH INSERT INTO foo (k, v) VALUES (1, '%s') APPLY BATCH",
                Strings.repeat("1", BATCH_SIZE_WARN_THRESHOLD_IN_BYTES)));

        List<String> warnings = rs.getExecutionInfo().getWarnings();
        assertThat(warnings).hasSize(1);
    }
}

@@ -928,172 +928,8 @@
  %7B%0A%0A
-    /**%0A     * This is Cassandra's default value, found in o.a.c.config.Config%0A     */%0A    private static final int BATCH_SIZE_WARN_THRESHOLD_IN_BYTES = 5 * 1024;%0A%0A
     
@@ -938,16 +938,16 @@
 verride%0A
+
     publ
@@ -1174,24 +1174,240 @@
 on_info() %7B%0A
+        // the default batch size warn threshold is 5 * 1024 bytes, but after CASSANDRA-10876 there must be%0A        // multiple mutations in a batch to trigger this warning so the batch includes 2 different inserts.%0A
         Resu
@@ -1470,17 +1470,47 @@
 ED BATCH
- 
+%5Cn%22 +%0A                        %22
 INSERT I
@@ -1544,93 +1544,214 @@
 %25s')
- APPLY BATCH%22,%0A                Strings.repeat(%221%22, BATCH_SIZE_WARN_THRESHOLD_IN_BYTES
+%5Cn%22 +%0A                        %22INSERT INTO foo (k, v) VALUES (2, '%25s')%5Cn%22 +%0A                        %22APPLY BATCH%22,%0A                Strings.repeat(%221%22, 2 * 1024),%0A                Strings.repeat(%221%22, 3 * 1024
 )));

Update WarningsTest for CASSANDRA-10786