Search in sources :

Example 26 with Concourse

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

the class CON649 method repro.

@Test
public void repro() throws IOException, TTransportException, InterruptedException {
    List<Thread> clients = Lists.newArrayList();
    Table<Long, String, String> expected = HashBasedTable.create();
    for (int i = 0; i < Runtime.getRuntime().availableProcessors(); ++i) {
        clients.add(new Thread(() -> {
            Concourse $client = server.connect();
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    long id = Random.getLong();
                    String key = Random.getSimpleString();
                    String value = Random.getSimpleString();
                    $client.add(key, value, id);
                    expected.put(id, key, value);
                    // allow some transports to go
                    Random.tinySleep();
                // through...
                } catch (Exception e) {
                    Thread.currentThread().interrupt();
                }
            }
        }));
    }
    clients.forEach(Thread::start);
    Thread.sleep(10000);
    Random.microSleep();
    server.stop();
    Path db = server.getDatabaseDirectory().resolve("default");
    List<Path> directories = ImmutableList.of(db.resolve("cpb"), db.resolve("csb"), db.resolve("ctb"));
    Map<String, AtomicInteger> counts = Maps.newLinkedHashMap();
    directories.forEach(directory -> {
        try {
            Files.list(directory).forEach(file -> {
                System.out.println(file);
                String name = file.getFileName().toString().split("\\.")[0];
                counts.computeIfAbsent(name, key -> new AtomicInteger(0)).incrementAndGet();
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    Set<Integer> distinct = Sets.newHashSet();
    counts.forEach((path, count) -> {
        System.out.println(path + " = " + count);
        distinct.add(count.get());
    });
    System.out.println(counts.size());
    server.start();
    client = server.connect();
    for (Cell<Long, String, String> cell : expected.cellSet()) {
        long record = cell.getRowKey();
        String key = cell.getColumnKey();
        Object value = cell.getValue();
        Assert.assertEquals(value, client.get(key, record));
    }
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) TTransportException(org.apache.thrift.transport.TTransportException) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) HashBasedTable(com.google.common.collect.HashBasedTable) Maps(com.google.common.collect.Maps) Concourse(com.cinchapi.concourse.Concourse) Sets(com.google.common.collect.Sets) Random(com.cinchapi.concourse.util.Random) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Cell(com.google.common.collect.Table.Cell) Assert(org.junit.Assert) Path(java.nio.file.Path) ClientServerTest(com.cinchapi.concourse.test.ClientServerTest) Table(com.google.common.collect.Table) Concourse(com.cinchapi.concourse.Concourse) IOException(java.io.IOException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) ClientServerTest(com.cinchapi.concourse.test.ClientServerTest)

Example 27 with Concourse

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

the class PluginSecurityTest method testPluginMethodsInheritsUserPermission.

@Test
public void testPluginMethodsInheritsUserPermission() {
    server.executeCli("users", "create jeff --set-password jeff --set-role user --password admin");
    Concourse client2 = server.connect("jeff", "jeff");
    try {
        client2.invokePlugin(TestPlugin.class.getName(), "inventory");
        Assert.fail();
    } catch (Exception e) {
        server.executeCli("users", "grant jeff --permission read --password admin");
        Assert.assertEquals(ImmutableSet.of(), client2.invokePlugin(TestPlugin.class.getName(), "inventory"));
    }
}
Also used : Concourse(com.cinchapi.concourse.Concourse) Test(org.junit.Test) ClientServerTest(com.cinchapi.concourse.test.ClientServerTest) PluginTest(com.cinchapi.concourse.test.PluginTest)

Example 28 with Concourse

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

the class PermissionTest method testDriverIsUsableAfterPermissionException.

@Test
public void testDriverIsUsableAfterPermissionException() {
    createUser("jeff", "jeff", "user");
    Concourse client2 = Concourse.connect(SERVER_HOST, SERVER_PORT, "jeff", "jeff");
    grant("jeff", "read", "");
    long record = client.add("foo", "foo");
    try {
        client2.set("foo", "bar", record);
        Assert.fail();
    } catch (PermissionException e) {
        Assert.assertEquals("foo", client2.get("foo", record));
    }
}
Also used : PermissionException(com.cinchapi.concourse.PermissionException) Concourse(com.cinchapi.concourse.Concourse) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) 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