Search in sources :

Example 16 with Concourse

use of com.cinchapi.concourse.Concourse in project concourse by cinchapi.

the class Upgrade0_11_0_1Test method preUpgradeActions.

@Override
protected void preUpgradeActions() {
    envs = new String[] { "foo", "bar" };
    ClientServerTests.insertRandomData(server, envs);
    for (String env : envs) {
        Concourse concourse = server.connect("admin", "admin", env);
        try {
            Set<Long> inventory = concourse.inventory();
            Map<Long, Map<String, Set<Object>>> records = Maps.newHashMap();
            for (long record : inventory) {
                if (TestData.getScaleCount() % 3 == 0) {
                    records.put(record, concourse.select(record));
                }
            }
            Map<String, Map<Object, Set<Long>>> indexes = Maps.newLinkedHashMap();
            Set<String> keys = concourse.describe();
            for (String key : concourse.describe()) {
                if (TestData.getScaleCount() % 3 == 0) {
                    indexes.put(key, concourse.browse(key));
                }
            }
            tests.put(env, con -> {
                System.out.println("Checking inventory...");
                Assert.assertEquals(inventory, con.inventory());
                System.out.println("Checking random records...");
                for (Entry<Long, Map<String, Set<Object>>> entry : records.entrySet()) {
                    Map<String, Set<Object>> expected = entry.getValue();
                    long record = entry.getKey();
                    Assert.assertEquals(expected, con.select(record));
                }
                System.out.println("Checking dictionary...");
                Assert.assertEquals(keys, con.describe());
                System.out.println("Checking random indexes...");
                for (Entry<String, Map<Object, Set<Long>>> entry : indexes.entrySet()) {
                    Map<Object, Set<Long>> expected = entry.getValue();
                    String key = entry.getKey();
                    Assert.assertEquals(expected, con.browse(key));
                }
            });
        } finally {
            concourse.close();
        }
    }
}
Also used : Set(java.util.Set) Concourse(com.cinchapi.concourse.Concourse) Map(java.util.Map)

Example 17 with Concourse

use of com.cinchapi.concourse.Concourse in project concourse by cinchapi.

the class CON171 method repro2.

@Test(expected = TransactionException.class)
public void repro2() {
    Concourse client2 = Concourse.connect(SERVER_HOST, SERVER_PORT, "admin", "admin");
    client.stage();
    client.find("foo", Operator.EQUALS, "bar");
    client2.add("foo", "bar", 1);
    Assert.assertTrue(client.find("foo", Operator.EQUALS, "bar").isEmpty());
}
Also used : Concourse(com.cinchapi.concourse.Concourse) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 18 with Concourse

use of com.cinchapi.concourse.Concourse in project concourse by cinchapi.

the class CON75 method repro.

@Test
public void repro() {
    final AtomicBoolean running = new AtomicBoolean(true);
    final AtomicBoolean caughtException = new AtomicBoolean(false);
    int count = 0;
    for (int i = 0; i < 247; i++) {
        client.add("__table__", "youtube", i);
        client.add("count", i, i);
        count = i;
    }
    final int value = count;
    final Concourse client2 = Concourse.connect(SERVER_HOST, SERVER_PORT, "admin", "admin");
    final Concourse client3 = Concourse.connect(SERVER_HOST, SERVER_PORT, "admin", "admin");
    Thread a = new Thread(new Runnable() {

        @Override
        public void run() {
            int count = value;
            while (running.get()) {
                try {
                    client2.add("__table__", "youtube", count);
                    client2.add("count", count, count);
                    count++;
                } catch (RuntimeException e) {
                    caughtException.set(true);
                    running.set(false);
                }
            }
        }
    });
    Thread b = new Thread(new Runnable() {

        @Override
        public void run() {
            while (running.get()) {
                try {
                    client3.clear("count", client.search("__table__", "youtube"));
                } catch (RuntimeException e) {
                    caughtException.set(true);
                    running.set(false);
                }
            }
        }
    });
    a.start();
    b.start();
    StandardActions.wait(1500, TimeUnit.MILLISECONDS);
    running.set(false);
    Assert.assertFalse(caughtException.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Concourse(com.cinchapi.concourse.Concourse) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 19 with Concourse

use of com.cinchapi.concourse.Concourse in project concourse by cinchapi.

the class ClientServerTests method insertRandomData.

/**
 * A utility method to populate the test server with random data.
 *
 * @param server the {@link ManagedConcourseServer} used in the test
 * @param environments the environments in which random data should be
 *            inserted
 */
public static void insertRandomData(ManagedConcourseServer server, String... environments) {
    for (String environment : environments) {
        Path directory = server.getDatabaseDirectory().resolve(environment).resolve("cpb");
        Concourse client = server.connect("admin", "admin", environment);
        try {
            int count = Random.getScaleCount();
            Stream<Path> stream = null;
            try {
                while (stream == null || stream.count() < count) {
                    client.add(Random.getSimpleString(), Random.getObject());
                    if (stream != null) {
                        stream.close();
                    }
                    stream = java.nio.file.Files.list(directory);
                }
            } finally {
                stream.close();
            }
        } catch (IOException e) {
            throw CheckedExceptions.throwAsRuntimeException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) Concourse(com.cinchapi.concourse.Concourse) IOException(java.io.IOException)

Example 20 with Concourse

use of com.cinchapi.concourse.Concourse in project concourse by cinchapi.

the class ManagedConcourseServerTest method testTranslateOrderBetweenClientAndServer.

@Test
public void testTranslateOrderBetweenClientAndServer() {
    server.start();
    Concourse concourse = server.connect();
    concourse.select(ImmutableList.of(1L, 2L), Order.by("name"));
    // lack of Exception means the test passes
    Assert.assertTrue(true);
}
Also used : Concourse(com.cinchapi.concourse.Concourse) Test(org.junit.Test)

Aggregations

Concourse (com.cinchapi.concourse.Concourse)28 Test (org.junit.Test)23 ConcourseIntegrationTest (com.cinchapi.concourse.test.ConcourseIntegrationTest)10 PermissionException (com.cinchapi.concourse.PermissionException)2 Timestamp (com.cinchapi.concourse.Timestamp)2 ManagedConcourseServer (com.cinchapi.concourse.server.ManagedConcourseServer)2 ClientServerTest (com.cinchapi.concourse.test.ClientServerTest)2 ConcourseCodebase (com.cinchapi.concourse.util.ConcourseCodebase)2 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ConnectionPool (com.cinchapi.concourse.ConnectionPool)1 Link (com.cinchapi.concourse.Link)1 TransactionException (com.cinchapi.concourse.TransactionException)1 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)1 PluginTest (com.cinchapi.concourse.test.PluginTest)1 AccessToken (com.cinchapi.concourse.thrift.AccessToken)1