/*
 * 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.cassandra.distributed.test.accord;

import java.io.IOException;

import org.junit.Test;

import org.apache.cassandra.distributed.Cluster;
import org.apache.cassandra.schema.TableId;

import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL;
import static org.apache.cassandra.distributed.api.Feature.NETWORK;

public class AccordDropTableTest extends AccordDropTableBase
{
    @Test
    public void dropTable() throws IOException
    {
        int examples = 5;
        int steps = 5;
        try (Cluster cluster = Cluster.build(3)
                                      .withoutVNodes()
                                      .withConfig(c -> c.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)
                                                       .set("accord.shard_durability_target_splits", 4)
                                                       .set("auto_snapshot", false))
                                      .start())
        {
            fixDistributedSchemas(cluster);
            init(cluster);
            for (int i = 0; i < examples; i++)
            {
                int j = 0;
                try
                {
                    addChaos(cluster, i);
                    TableId id = createTable(cluster);
                    for (j = 0; j < steps; j++)
                        doTxn(cluster, j);
                    dropTable(cluster);
                    validateAccord(cluster, id);
                }
                catch (Throwable t)
                {
                    throw new AssertionError("Error at example " + i + ", " + j, t);
                }
            }
        }
    }
}
