Search in sources :

Example 1 with RandomStringGenerator

use of org.apache.commons.text.RandomStringGenerator in project docker-maven-plugin by fabric8io.

the class LogRequestorTest method testAllStreams.

@Test
public void testAllStreams() throws Exception {
    final Random rand = new Random();
    final int upperBound = 1024;
    RandomStringGenerator randomGenerator = new RandomStringGenerator.Builder().build();
    final Streams type0 = Streams.STDIN;
    final String msg0 = randomGenerator.generate(rand.nextInt(upperBound));
    final ByteBuffer buf0 = messageToBuffer(type0, msg0);
    final Streams type1 = Streams.STDOUT;
    final String msg1 = randomGenerator.generate(rand.nextInt(upperBound));
    final ByteBuffer buf1 = messageToBuffer(type1, msg1);
    final Streams type2 = Streams.STDERR;
    final String msg2 = randomGenerator.generate(rand.nextInt(upperBound));
    final ByteBuffer buf2 = messageToBuffer(type2, msg2);
    final ByteBuffer body = combineBuffers(buf0, buf1, buf2);
    final InputStream inputStream = new ByteArrayInputStream(body.array());
    setupMocks(inputStream);
    new LogRequestor(client, urlBuilder, containerId, callback).fetchLogs();
    new Verifications() {

        {
            callback.log(type0.type, (Timestamp) any, msg0);
            callback.log(type1.type, (Timestamp) any, msg1);
            callback.log(type2.type, (Timestamp) any, msg2);
        }
    };
}
Also used : RandomStringGenerator(org.apache.commons.text.RandomStringGenerator) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Verifications(mockit.Verifications) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with RandomStringGenerator

use of org.apache.commons.text.RandomStringGenerator in project docker-maven-plugin by fabric8io.

the class LogRequestorTest method testStdoutMessage.

@Test
public void testStdoutMessage() throws Exception {
    final Streams type = Streams.STDOUT;
    RandomStringGenerator randomGenerator = new RandomStringGenerator.Builder().build();
    final String message0 = randomGenerator.generate(257);
    final String message1 = "test test";
    final String message2 = randomGenerator.generate(666);
    final ByteBuffer body = responseContent(type, message0, message1, message2);
    final InputStream inputStream = new ByteArrayInputStream(body.array());
    setupMocks(inputStream);
    new LogRequestor(client, urlBuilder, containerId, callback).fetchLogs();
    new Verifications() {

        {
            callback.log(type.type, (Timestamp) any, message0);
            callback.log(type.type, (Timestamp) any, message1);
            callback.log(type.type, (Timestamp) any, message2);
        }
    };
}
Also used : RandomStringGenerator(org.apache.commons.text.RandomStringGenerator) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Verifications(mockit.Verifications) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with RandomStringGenerator

use of org.apache.commons.text.RandomStringGenerator in project openmeetings by apache.

the class AbstractCryptTest method get.

private static List<String> get(int count) {
    Random rnd = new Random();
    List<String> l = new ArrayList<>(count + 1);
    l.add("");
    RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('!', '}').usingRandom(rnd::nextInt).build();
    for (int i = 0; i < count; ++i) {
        l.add(generator.generate(rnd.nextInt(256)));
    }
    return l;
}
Also used : RandomStringGenerator(org.apache.commons.text.RandomStringGenerator) Random(java.util.Random) ArrayList(java.util.ArrayList)

Example 4 with RandomStringGenerator

use of org.apache.commons.text.RandomStringGenerator in project sqlg by pietermartin.

the class AbstractLabel method ensureIndexExists.

public Index ensureIndexExists(final IndexType indexType, final List<PropertyColumn> properties) {
    String prefix = this instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX;
    SchemaTable schemaTable = SchemaTable.of(this.getSchema().getName(), this.getLabel());
    String indexName = this.sqlgGraph.getSqlDialect().indexName(schemaTable, prefix, properties.stream().map(PropertyColumn::getName).collect(Collectors.toList()));
    if (indexName.length() > this.sqlgGraph.getSqlDialect().getMaximumIndexNameLength()) {
        // name was random, need to check the properties list
        for (Index idx : this.getIndexes().values()) {
            if (idx.getProperties().equals(properties)) {
                return idx;
            }
        }
        this.getSchema().getTopology().lock();
        for (Index idx : this.getIndexes().values()) {
            if (idx.getProperties().equals(properties)) {
                return idx;
            }
        }
        RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('a', 'z').build();
        indexName = generator.generate(this.sqlgGraph.getSqlDialect().getMaximumIndexNameLength());
        return this.createIndex(indexName, indexType, properties);
    } else {
        Optional<Index> indexOptional = this.getIndex(indexName);
        if (!indexOptional.isPresent()) {
            this.getSchema().getTopology().lock();
            indexOptional = this.getIndex(indexName);
            if (!indexOptional.isPresent()) {
                return this.createIndex(indexName, indexType, properties);
            } else {
                return indexOptional.get();
            }
        } else {
            return indexOptional.get();
        }
    }
}
Also used : RandomStringGenerator(org.apache.commons.text.RandomStringGenerator)

Aggregations

RandomStringGenerator (org.apache.commons.text.RandomStringGenerator)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Random (java.util.Random)2 Verifications (mockit.Verifications)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1