Skip to content

Instantly share code, notes, and snippets.

@iSignal
Created August 29, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iSignal/8b7686b7d833fb51a2584e1de2534628 to your computer and use it in GitHub Desktop.
Save iSignal/8b7686b7d833fb51a2584e1de2534628 to your computer and use it in GitHub Desktop.
// Copyright (c) YugaByte, 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 org.yb.cql;
import java.util.*;
import org.junit.BeforeClass;
import org.junit.Test;
import com.datastax.driver.core.BatchStatement;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.core.UDTValue;
import org.yb.minicluster.BaseMiniClusterTest;
import org.yb.minicluster.MiniYBCluster;
import org.yb.minicluster.RocksDBMetrics;
import static org.yb.AssertionWrappers.assertEquals;
import static org.yb.AssertionWrappers.assertFalse;
import static org.yb.AssertionWrappers.assertNotNull;
import static org.yb.AssertionWrappers.assertNull;
import static org.yb.AssertionWrappers.assertTrue;
import static org.yb.AssertionWrappers.fail;
import org.yb.YBTestRunner;
import org.junit.runner.RunWith;
@RunWith(value=YBTestRunner.class)
public class TestListUpdate extends BaseCQLTest {
@BeforeClass
public static void SetUpBeforeClass() throws Exception {
BaseMiniClusterTest.tserverArgs.add("--allow_index_table_read_write");
BaseCQLTest.setUpBeforeClass();
}
public int getTestMethodTimeoutSec() {
return 6000; // long
}
@Test
public void testListUpdate() throws Exception {
LOG.info("starting test list update");
session.execute("CREATE TYPE rangetype (startid int, endid int);");
session.execute("CREATE TABLE test_list_update (id UUID PRIMARY KEY, "
+ "ranges LIST<FROZEN<rangetype>>) WITH transactions = { 'enabled' : true};");
final PreparedStatement statement = session.prepare(
"UPDATE test_list_update SET ranges = ranges + [{startid:?, endid:?}, {startid:?, endid:?}] "
+ " WHERE id=F8B9FF57-5DFB-4DB3-B2FA-5EDC99A626DC;");
//session.execute(statement.bind(1,2,3,4));
long start = System.currentTimeMillis();
List<Thread> threads = new ArrayList<Thread>();
int NUM_KEYS = 1000;
int NUM_THREADS = 40;
while (threads.size() != NUM_THREADS) {
Thread thread = new Thread(() -> {
try {
Thread.sleep(5);
} catch (InterruptedException e) {}
int key = 0;
int mythreadid = (int)Thread.currentThread().getId();
LOG.info("starting thread with id " + mythreadid);
int uniqid = 100000 * mythreadid;
while (key < NUM_KEYS) {
session.execute(statement.bind(mythreadid, uniqid + key, mythreadid, uniqid + key + 1));
key += 2;
}
});
thread.start();
threads.add(thread);
}
for (Thread thread : threads) {
thread.join();
}
long end = System.currentTimeMillis();
int numListEntries = 0;
for (Row row : session.execute("select * FROM test_list_update;")) {
//LOG.info("printing results test_list_update " + row.toString());
List<UDTValue> ranges = row.getList(1, UDTValue.class);
numListEntries += ranges.size();
//for (UDTValue range: ranges) {
//LOG.info(range.toString());
//}
}
assertEquals(numListEntries, NUM_THREADS * NUM_KEYS);
session.execute("drop table test_list_update;");
LOG.info("Updating entries for test_list_update took " + (end - start)/1000 +
" secs to run, added " + NUM_KEYS + " list entries * " +
NUM_THREADS + " threads");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment