Java 类org.apache.commons.lang3.RandomUtils 实例源码

项目:RedisDirectory    文件:Main.java   
private static Document addDocument(int i) {
    Document document = new Document();
    document.add(new StringField("key1", "key" + i, Field.Store.YES));
    document.add(new IntField("key2", i * 100000, Field.Store.YES));
    document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES));
    document.add(new LongField("key4", (long) i * 100000, Field.Store.YES));
    document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES));
    document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES));
    document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
    document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5))));
    document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000)));
    document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000)));
    document.add(new LongField("key11", (long) i * 50000, Field.Store.YES));
    document.add(new IntField("key12", i * 50000, Field.Store.YES));
    document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES));
    document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES));
    document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES));
    return document;
}
项目:RedisDirectory    文件:TestLucene.java   
private Document addDocument(int i) {
    Document document = new Document();
    document.add(new StringField("key1", "key" + i, Field.Store.YES));
    document.add(new IntField("key2", i * 100000, Field.Store.YES));
    document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES));
    document.add(new LongField("key4", (long) i * 100000, Field.Store.YES));
    document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES));
    document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES));
    document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
    document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5))));
    document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000)));
    document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000)));
    document.add(new LongField("key11", (long) i * 50000, Field.Store.YES));
    document.add(new IntField("key12", i * 50000, Field.Store.YES));
    document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES));
    document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES));
    document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES));
    return document;
}
项目:cyberduck    文件:S3ReadFeatureTest.java   
@Test
public void testDownloadGzip() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final int length = 1457;
    final byte[] content = RandomUtils.nextBytes(length);
    final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final InputStream in = new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback());
    assertNotNull(in);
    new StreamCopier(status, status).transfer(in, new NullOutputStream());
    assertEquals(content.length, status.getOffset());
    assertEquals(content.length, status.getLength());
    in.close();
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
项目:jigsaw-payment    文件:TestAccountRepository.java   
@Test
public void testCreateAndGet(){
    Account.Builder builder = Account.newBuilder();
    long uid = System.currentTimeMillis();
    long id = (uid * 10 + 1);
    builder.setId(id);
    builder.setBalance(RandomUtils.nextInt(0, 1000));
    builder.setCreateTime(System.currentTimeMillis());
    builder.setFeeUnit(FeeUnit.CNY);
    builder.setFrozen(RandomUtils.nextInt(0, 100));
    builder.setIncome(RandomUtils.nextInt(0, 1000));
    builder.setSandbox(false);
    builder.setKey(System.currentTimeMillis());
    builder.setNotification(AccountNotification.EMAIL);
    builder.setPermissions(AccountPermission.ALLOW_IN_VALUE | AccountPermission.ALLOW_OUT_VALUE);
    builder.setRank(1);
    builder.setRiskLevel(Account.RiskLevel.HIGH);
    this.accountRepository.create(builder.build());


}
项目:janusgraph-utils    文件:IdStore.java   
/**
 * Get a random integer except the one(s) in the the ex
 * @param vType vertex label
 * @param ex unsorted list of unique numbers to exclude
 * @return an integer not in the exclude list or -1 if not found
 */
public int getRandomIdWithException(String vType, List<Integer> ex) {
    int start = idBean.getMinId(vType);
    int end = idBean.getMaxId(vType);
    boolean found = false;
    int rnd = -1;
    if (ex.size() > (end - start))
        return rnd;
    while (!found) {
        rnd = RandomUtils.nextInt(start, end + 1);
        if (false == ex.contains(rnd)) {
            found = true;
        }
    }
    return rnd;
}
项目:cyberduck    文件:S3ReadFeatureTest.java   
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final int length = 2048;
    final byte[] content = RandomUtils.nextBytes(length);
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final CountingInputStream in = new CountingInputStream(new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
项目:xm-ms-entity    文件:XmEntityGeneratorService.java   
private Set<Location> generateLocations(LocationSpec locationSpec) {
    Set<Location> result = new HashSet<>();

    List<Location> originalLocationStubs = getLocationStubs();
    val locationStubs = originalLocationStubs.stream().filter(l -> RandomUtils.nextBoolean()).collect(toList());
    if (isEmpty(locationStubs)) {
        int randomLocationPosition = RandomUtils.nextInt(0, originalLocationStubs.size() - 1);
        Location randomLocationStub = originalLocationStubs.get(randomLocationPosition);
        locationStubs.add(randomLocationStub);
    }

    int locationsLimit = min(locationSpec.getMax(), locationStubs.size());
    int countLocations = RandomUtils.nextInt(1, locationsLimit);

    IntStream.range(0, countLocations).forEachOrdered(i -> {
        Location locationStub = locationStubs.get(i);
        updateLocationStubToLocation(locationSpec, locationStub);
        result.add(locationStub);
    });

    return result;
}
项目:cyberduck    文件:LocalWriteFeatureTest.java   
@Test
public void testWriteTildeFilename() throws Exception {
    final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname()));
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final LocalWriteFeature feature = new LocalWriteFeature(session);
    final Path workdir = new LocalHomeFinderFeature(session).find();
    final Path test = new Path(workdir, String.format("~$%s", new AsciiRandomStringService().random()), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(2048);
    final TransferStatus status = new TransferStatus().length(content.length);
    final OutputStream out = feature.write(test, status, new DisabledConnectionCallback());
    new StreamCopier(status, status).withOffset(status.getOffset()).withLimit(status.getLength()).transfer(new ByteArrayInputStream(content), out);
    out.flush();
    out.close();
    final ByteArrayOutputStream b = new ByteArrayOutputStream(content.length);
    IOUtils.copy(new LocalReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()), b);
    assertArrayEquals(content, b.toByteArray());
    assertTrue(new DefaultFindFeature(session).find(test));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(test).getSize());
    new LocalDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:SpectraMultipleDeleteFeatureTest.java   
@Test
public void testDeleteFile() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(
            System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key")
    ));
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("cyberduck", EnumSet.of(Path.Type.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(1024);
    final HttpResponseOutputStream<StorageObject> out = new S3WriteFeature(session).write(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.write(content, out);
    out.close();
    assertTrue(new S3FindFeature(session).find(test));
    new S3MultipleDeleteFeature(session).delete(Arrays.asList(test, test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    assertFalse(new S3FindFeature(session).find(test));
    session.close();
}
项目:randomito-all    文件:NumberGenerator.java   
@Override
public Object generate(DefaultContext ctx) throws Exception {
    Number number = Number.class.cast(RandomUtils.nextInt(0, 127));
    Class<?> type = ctx.getType();
    if (!type.isPrimitive()) {
        return ReflectionUtils.stringToNumber(number, type);
    }
    if (type == Integer.TYPE) {
        return number.intValue();
    } else if (type == Long.TYPE) {
        return number.longValue();
    } else if (type == Byte.TYPE) {
        return number.byteValue();
    } else if (type == Float.TYPE) {
        return number.floatValue();
    } else if (type == Double.TYPE) {
        return number.doubleValue();
    } else if (type == Short.TYPE) {
        return number.shortValue();
    }
    throw new RandomitoException("did not generate number value for type: " + type);
}
项目:cyberduck    文件:CopyWorkerTest.java   
@Test
public void testCopyFile() throws Exception {
    final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new DriveDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new DriveWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new DriveReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
项目:azeroth    文件:MybatisTest.java   
@Test
public void testRwRouteWithTransaction2() {

    mapper.findByStatus((short) 1);

    transactionTemplate.execute(new TransactionCallback<Void>() {
        @Override
        public Void doInTransaction(TransactionStatus status) {

            mapper.findByStatus((short) 2);

            UserEntity entity = new UserEntity();
            entity.setCreatedAt(new Date());
            entity.setEmail(RandomStringUtils.random(6, true, true) + "@163.com");
            entity.setMobile("13800" + RandomUtils.nextLong(100000, 999999));
            entity.setType((short) 1);
            entity.setStatus((short) 1);
            mapper.insert(entity);

            mapper.findByStatus((short) 2);

            return null;
        }
    });
    System.out.println();
}
项目:cyberduck    文件:DefaultCopyFeatureTest.java   
@Test
public void testCopy() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password")
    ));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());

    final Path source = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))).touch(source, new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(524);
    final TransferStatus status = new TransferStatus().length(content.length);
    final OutputStream out = new SFTPWriteFeature(session).write(source, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(new ByteArrayInputStream(content), out);
    out.close();
    new DefaultCopyFeature(session).copy(source, target, new TransferStatus(), new DisabledConnectionCallback());
    assertTrue(new DefaultFindFeature(session).find(source));
    assertTrue(new DefaultFindFeature(session).find(target));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(target).getSize());
    new SFTPDeleteFeature(session).delete(Arrays.asList(source, target), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
项目:cyberduck    文件:FileBufferTest.java   
@Test
public void testSplit() throws Exception {
    final FileBuffer buffer = new FileBuffer();
    buffer.truncate(200L);
    assertEquals(200L, buffer.length(), 0L);
    final byte[] chunk = RandomUtils.nextBytes(100);
    buffer.write(chunk, 0L);
    assertEquals(200L, buffer.length(), 0L);
    final byte[] compare = new byte[100];
    buffer.read(compare, 0L);
    final byte[] empty = new byte[100];
    buffer.read(empty, 100L);
    assertArrayEquals(new byte[100], empty);
    final byte[] overFileEnd = new byte[150];
    assertEquals(100L, buffer.read(overFileEnd, 0L));
    assertNotEquals(IOUtils.EOF, buffer.read(empty, 100L));
    assertEquals(IOUtils.EOF, buffer.read(new byte[1], 200L));
}
项目:cyberduck    文件:OneDriveBufferWriteFeatureTest.java   
@Test
public void testWriteZeroLength() throws Exception {
    final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(0);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    new StreamCopier(status, status).transfer(in, out);
    in.close();
    out.flush();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:OneDriveWriteFeatureTest.java   
@Test
public void testWrite() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final byte[] buffer = new byte[32 * 1024];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:OneDriveWriteFeatureTest.java   
@Test
public void testWriteUmlaut() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(2048);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, String.format("%sä", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    assertEquals(content.length, IOUtils.copyLarge(in, out));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:OneDriveWriteFeatureTest.java   
@Test(expected = InteroperabilityException.class)
public void testWriteUnknownLength() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final byte[] buffer = new byte[1 * 1024];
    try {
        assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    }
    catch(OneDriveAPIException e) {
        final BackgroundException failure = new OneDriveExceptionMappingService().map(e);
        assertTrue(failure.getDetail().contains("Invalid Content-Range header value.")
                || failure.getDetail().contains("Bad Request. The Content-Range header is missing or malformed."));
        throw failure;
    }
}
项目:cyberduck    文件:CopyWorkerTest.java   
@Test
public void testCopyFile() throws Exception {
    final Path home = new OneDriveHomeFinderFeature(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new OneDriveDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new OneDriveWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new OneDriveFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new OneDriveFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new OneDriveReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
项目:cyberduck    文件:MoveWorkerTest.java   
@Test
public void testMoveSameFolderCryptomator() throws Exception {
    final Path home = new OneDriveHomeFinderFeature(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new OneDriveDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new OneDriveWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final MoveWorker worker = new MoveWorker(Collections.singletonMap(source, target), PathCache.empty(), new TestPasswordStore(), new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledProgressListener(), new DisabledTranscriptListener());
    worker.run(session);
    assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new OneDriveReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new CryptoDeleteFeature(session, new OneDriveDeleteFeature(session), cryptomator).delete(Arrays.asList(target, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:MantaWriteFeatureTest.java   
@Test
public void testWrite() throws Exception {
    final MantaWriteFeature feature = new MantaWriteFeature(session);
    final Path container = new MantaDirectoryFeature(session).mkdir(randomDirectory(), "", new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final byte[] buffer = new byte[32 * 1024];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new MantaReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new MantaDeleteFeature(session).delete(Collections.singletonList(container), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:MantaWriteFeatureTest.java   
@Test
public void testWriteUnknownLength() throws Exception {
    final MantaWriteFeature feature = new MantaWriteFeature(session);
    final Path container = randomDirectory();
    new MantaDirectoryFeature(session).mkdir(container, "", new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);

    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final int alloc = 1024;
    final byte[] buffer = new byte[alloc];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    out.close();
    final PathAttributes found = new MantaAttributesFinderFeature(session).find(file);
    assertEquals(found.getSize(), content.length);
    new MantaDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
项目:cyberduck    文件:CryptoOutputStreamTest.java   
@Test
public void testSmallChunksToWrite() throws Exception {
    final CryptoVault vault = this.getVault();
    final ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
    final FileHeader header = vault.getCryptor().fileHeaderCryptor().create();
    final CryptoOutputStream<?> stream = new CryptoOutputStream<>(new StatusOutputStream<Void>(cipherText) {
        @Override
        public Void getStatus() throws BackgroundException {
            return null;
        }
    }, vault.getCryptor(), header, new RandomNonceGenerator(), 0);

    final byte[] part1 = RandomUtils.nextBytes(1024);
    final byte[] part2 = RandomUtils.nextBytes(1024);
    stream.write(part1, 0, part1.length);
    stream.write(part2, 0, part2.length);
    stream.close();

    final byte[] read = new byte[part1.length + part2.length];
    final byte[] expected = ByteBuffer.allocate(part1.length + part2.length).put(part1).put(part2).array();
    final CryptoInputStream cryptoInputStream = new CryptoInputStream(new ByteArrayInputStream(cipherText.toByteArray()), vault.getCryptor(), header, 0);
    assertEquals(expected.length, cryptoInputStream.read(read));
    cryptoInputStream.close();

    assertArrayEquals(expected, read);
}
项目:cyberduck    文件:CryptoOutputStreamTest.java   
@Test
public void testWriteWithChunkSize() throws Exception {
    final CryptoVault vault = this.getVault();
    final ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
    final FileHeader header = vault.getCryptor().fileHeaderCryptor().create();
    final CryptoOutputStream<?> stream = new CryptoOutputStream<>(new StatusOutputStream<Void>(cipherText) {
        @Override
        public Void getStatus() throws BackgroundException {
            return null;
        }
    }, vault.getCryptor(), header, new RandomNonceGenerator(), 0);

    final byte[] cleartext = RandomUtils.nextBytes(vault.getCryptor().fileContentCryptor().cleartextChunkSize());
    stream.write(cleartext, 0, cleartext.length);
    stream.close();

    final byte[] read = new byte[cleartext.length];
    final CryptoInputStream cryptoInputStream = new CryptoInputStream(new ByteArrayInputStream(cipherText.toByteArray()), vault.getCryptor(), header, 0);
    assertEquals(cleartext.length, cryptoInputStream.read(read));
    cryptoInputStream.close();

    assertArrayEquals(cleartext, read);
}
项目:cyberduck    文件:CryptoOutputStreamTest.java   
@Test
public void testWriteLargeChunk() throws Exception {
    final CryptoVault vault = this.getVault();
    final ByteArrayOutputStream cipherText = new ByteArrayOutputStream();
    final FileHeader header = vault.getCryptor().fileHeaderCryptor().create();
    final CryptoOutputStream<?> stream = new CryptoOutputStream<>(new StatusOutputStream<Void>(cipherText) {
        @Override
        public Void getStatus() throws BackgroundException {
            return null;
        }
    }, vault.getCryptor(), header, new RandomNonceGenerator(), 0);

    final byte[] cleartext = RandomUtils.nextBytes(vault.getCryptor().fileContentCryptor().cleartextChunkSize() + 1);
    stream.write(cleartext, 0, cleartext.length);
    stream.close();

    final byte[] read = new byte[cleartext.length];
    final CryptoInputStream cryptoInputStream = new CryptoInputStream(new ByteArrayInputStream(cipherText.toByteArray()), vault.getCryptor(), header, 0);
    IOUtils.readFully(cryptoInputStream, read);
    cryptoInputStream.close();

    assertArrayEquals(cleartext, read);
}
项目:openvisualtraceroute    文件:JpcapTraceRoute.java   
/**
 * @return
 */
private ICMPPacket createPacket(final InetAddress destIp, final short hop) {
    final ICMPPacket packet = new ICMPPacket();
    packet.type = ICMPPacket.ICMP_ECHO;
    packet.seq = 100;
    packet.id = (short) RandomUtils.nextInt(0, 100);
    packet.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 0, IPPacket.IPPROTO_ICMP, _deviceIp, destIp);
    final String data = "ovtr";
    packet.data = data.getBytes();
    final EthernetPacket ether = new EthernetPacket();
    ether.frametype = EthernetPacket.ETHERTYPE_IP;
    ether.src_mac = _device.mac_address;
    ether.dst_mac = _gatewayMac;
    packet.datalink = ether;
    packet.hop_limit = hop;
    return packet;
}
项目:hkdf    文件:HKDFTest.java   
@Test
public void checkLength() throws Exception {
    int[] counts = {1, 4, 7, 8, 16, 20, 24, 36, 48, 64, 69, 72, 96, 128, 256, 512};
    byte[] ikm;
    byte[] salt;

    for (int i : counts) {
        ikm = RandomUtils.nextBytes(i);
        salt = RandomUtils.nextBytes(i * 2);
        checkLength(HKDF.fromHmacSha256().extract(salt, ikm), 32);
        checkLength(HKDF.fromHmacSha256().extract(null, ikm), 32);
        checkLength(HKDF.fromHmacSha256().extract(new byte[0], ikm), 32);
        checkLength(HKDF.fromHmacSha512().extract(salt, ikm), 64);
        checkLength(HKDF.fromHmacSha512().extract(null, ikm), 64);
        checkLength(HKDF.from(HkdfMacFactory.Default.hmacSha1()).extract(salt, ikm), 20);
        checkLength(HKDF.from(new HkdfMacFactory.Default("HmacMD5")).extract(ikm, salt), 16);

        assertFalse(Arrays.equals(HKDF.fromHmacSha256().extract(salt, ikm), HKDF.fromHmacSha512().extract(salt, ikm)));
        assertFalse(Arrays.equals(HKDF.fromHmacSha256().extract(salt, ikm), HKDF.from(HkdfMacFactory.Default.hmacSha1()).extract(salt, ikm)));
    }
}
项目:cyberduck    文件:S3WriteFeatureTest.java   
@Test
public void testWrite() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);
    final Path home = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<StorageObject> writer = new CryptoWriteFeature<StorageObject>(session, new S3WriteFeature(session), cryptomator);
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
    status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status));
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
    assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
项目:cas-5.1.0    文件:AbstractAuthenticationHandler.java   
/**
 * Instantiates a new Abstract authentication handler.
 *
 * @param name Handler name.
 * @param servicesManager the services manager.
 * @param principalFactory the principal factory
 * @param order the order
 */
public AbstractAuthenticationHandler(final String name, final ServicesManager servicesManager, final PrincipalFactory principalFactory,
                                     final Integer order) {
    this.name = StringUtils.isNotBlank(name) ? name : getClass().getSimpleName();
    this.servicesManager = servicesManager;
    this.principalFactory = principalFactory == null ? new DefaultPrincipalFactory() : principalFactory;
    if (order == null) {
        this.order = RandomUtils.nextInt(1, Integer.MAX_VALUE);
    } else {
        this.order = order;
    }
}
项目:cyberduck    文件:FileBufferTest.java   
@Test
public void testTruncate() throws Exception {
    final FileBuffer buffer = new FileBuffer();
    assertEquals(0L, buffer.length(), 0L);
    final byte[] chunk = RandomUtils.nextBytes(100);
    buffer.write(chunk, 0L);
    assertEquals(100L, buffer.length(), 0L);
    buffer.truncate(1L);
    assertEquals(1L, buffer.length(), 0L);
    final byte[] read = new byte[1];
    assertEquals(1, buffer.read(read, 0L));
    assertEquals(chunk[0], read[0]);
    assertEquals(1L, buffer.length(), 0L);
}
项目:nan    文件:WeightRandomLoadBalanceStrategyImpl.java   
@Override
public ProviderService select(List<ProviderService> providerServices) {
    //存放加权后的服务提供者列表
    List<ProviderService> providerList = Lists.newArrayList();
    for (ProviderService provider : providerServices) {
        int weight = provider.getWeight();
        for (int i = 0; i < weight; i++) {
            providerList.add(provider.copy());
        }
    }

    int MAX_LEN = providerList.size();
    int index = RandomUtils.nextInt(0, MAX_LEN - 1);
    return providerList.get(index);
}
项目:spring-boot-graph-day    文件:LoadUtil.java   
private LocalDate childBirth(LocalDate fatherBirthDate, LocalDate motherBirthDate) {
    LocalDate min = fatherBirthDate.isAfter(motherBirthDate) ? fatherBirthDate : motherBirthDate;

    return min.plusYears(RandomUtils.nextInt(18, 35))
            .plusMonths(RandomUtils.nextInt(0, 12))
            .plusDays(RandomUtils.nextInt(0, 28));
}
项目:automat    文件:BaseService.java   
protected void sleep(int millis) {
    try {
        Thread.sleep(RandomUtils.nextLong(10, millis));
    } catch (InterruptedException e) {
        logger.error("", e);
    }
}
项目:automat    文件:SendMsgService.java   
/** 发送验证码 */
private void sendRandomCode(String sender, SendMsg sendMsg, String cacheKey) {
    Integer random = RandomUtils.nextInt(123456, 999999);
    Map<String, String> param = InstanceUtil.newHashMap();
    param.put("code", random.toString());
    param.put("product", sender);
    if ("6".equals(sendMsg.getMsgType())) {
        param.put("", sendMsg.getParams());
    }
    sendMsg.setParams(JSON.toJSONString(param));
    CacheUtil.getCache().set(cacheKey, random.toString(), 60);
}
项目:abhot    文件:BlastServer.java   
@Override
public void run()
{
    logger.info("Blast Server Running");
    Stopwatch timer = Stopwatch.createStarted();

    while (m_keepRunning)
    {
        long now = System.currentTimeMillis();
        DataPoint dataPoint = m_longDataPointFactory.createDataPoint(now, 42);
        int row = RandomUtils.nextInt(0, m_numberOfRows);
        ImmutableSortedMap<String, String> tags = ImmutableSortedMap.of("row",
                String.valueOf(row), "host", "blast_server");

        try
        {
            m_datastore.putDataPoint(m_metricName, tags, dataPoint, m_ttl);
        }
        catch (DatastoreException e)
        {
            e.printStackTrace();
        }
        m_counter ++;

        if ((m_counter % 100000 == 0) && (timer.elapsed(TimeUnit.SECONDS) > m_durration))
            m_keepRunning = false;

    }
}
项目:xm-ms-entity    文件:XmEntityGeneratorService.java   
private void updateLocationStubToLocation(LocationSpec locationSpec, Location locationStub) {

        locationStub.typeKey(locationSpec.getKey()).name(randomAnyString() + " locations");

        if (RandomUtils.nextInt(1, 10) < 5) {
            locationStub.addressLine1(null).addressLine2(null).city(null).region(null);
        } else if (RandomUtils.nextInt(1, 10) > 5) {
            locationStub.latitude(null).longitude(null);
        }
        // TODO: change this when Country DB entity will be removed
        locationStub.setCountryKey(null);
    }
项目:xm-ms-entity    文件:XmEntityGeneratorService.java   
private Set<Tag> generateTags(TypeSpec typeSpec) {
    Set<Tag> tags = new HashSet<>();
    for (TagSpec tagSpec: randomCollectionElement(typeSpec.getTags())) {
        int countTags = RandomUtils.nextInt(1, MAX_TAGS_BY_TYPE);
        IntStream.range(0, countTags).forEach(i -> tags.add(createTag(tagSpec, i + 1)));
        log.debug("Generate {} tags for type {}", countTags, tagSpec.getKey());
    }
    return tags;
}
项目:amv-highmobility-cryptotool-wrapper    文件:CryptotoolOptionsImplTest.java   
@Test
public void itShouldHaveAnElegantConstructionMechanism() {
    long commandTimeoutInSeconds = RandomUtils.nextLong();
    CryptotoolOptions cryptotoolOptions = CryptotoolOptionsImpl.builder()
            .binaryExecutor(BinaryExecutorImpl.createDefault())
            .commandTimeout(Duration.ofSeconds(commandTimeoutInSeconds))
            .build();

    assertThat(cryptotoolOptions, is(notNullValue()));
    assertThat(cryptotoolOptions.getBinaryExecutor(), is(notNullValue()));
    assertThat(cryptotoolOptions.getCommandTimeout(), is(Duration.ofSeconds(commandTimeoutInSeconds)));
}
项目:cyberduck    文件:DropboxWriteFeatureTest.java   
@Test(expected = AccessDeniedException.class)
public void testWriteDS_Store() throws Exception {
    final DropboxWriteFeature write = new DropboxWriteFeature(session);
    final TransferStatus status = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(0);
    status.setLength(content.length);
    final Path test = new Path(new DefaultHomeFinderService(session).find(), ".DS_Store", EnumSet.of(Path.Type.file));
    final OutputStream out = write.write(test, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
}
项目:bird-java    文件:AbstractServiceImpl.java   
protected void sleep(int millis) {
    try {
        Thread.sleep(RandomUtils.nextLong(10, millis));
    } catch (InterruptedException e) {
        logger.error("", e);
    }
}