use of java.util.Random in project camel by apache.
the class JmxInstrumentationWithConnectorTest method setUp.
@Override
protected void setUp() throws Exception {
sleepForConnection = 3000;
registryPort = 30000 + new Random().nextInt(10000);
log.info("Using port " + registryPort);
url = "service:jmx:rmi:///jndi/rmi://localhost:" + registryPort + "/jmxrmi/camel";
// need to explicit set it to false to use non-platform mbs
System.setProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS, "false");
System.setProperty(JmxSystemPropertyKeys.CREATE_CONNECTOR, "true");
System.setProperty(JmxSystemPropertyKeys.REGISTRY_PORT, "" + registryPort);
super.setUp();
}
use of java.util.Random in project camel by apache.
the class PipelineConcurrentTest method testConcurrentPipeline.
public void testConcurrentPipeline() throws Exception {
int total = 200;
final int group = total / 20;
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(total);
ExecutorService executor = Executors.newFixedThreadPool(20);
for (int i = 0; i < 20; i++) {
final int threadCount = i;
executor.execute(new Runnable() {
public void run() {
int start = threadCount * group;
for (int i = 0; i < group; i++) {
try {
// do some random sleep to simulate spread in user activity
Thread.sleep(new Random().nextInt(10));
} catch (InterruptedException e) {
// ignore
}
template.sendBody(uri, "" + (start + i));
}
}
});
}
mock.assertIsSatisfied();
mock.expectsNoDuplicates(body());
executor.shutdown();
}
use of java.util.Random in project camel by apache.
the class FileUtil method createNewTempDir.
/**
* Creates a new temporary directory in the <tt>java.io.tmpdir</tt> directory.
*/
@Deprecated
private static File createNewTempDir() {
String s = System.getProperty("java.io.tmpdir");
File checkExists = new File(s);
if (!checkExists.exists()) {
throw new RuntimeException("The directory " + checkExists.getAbsolutePath() + " does not exist, please set java.io.tempdir" + " to an existing directory");
}
if (!checkExists.canWrite()) {
throw new RuntimeException("The directory " + checkExists.getAbsolutePath() + " is not writable, please set java.io.tempdir" + " to a writable directory");
}
// create a sub folder with a random number
Random ran = new Random();
int x = ran.nextInt(1000000);
File f = new File(s, "camel-tmp-" + x);
int count = 0;
// Let us just try 100 times to avoid the infinite loop
while (!f.mkdir()) {
count++;
if (count >= 100) {
throw new RuntimeException("Camel cannot a temp directory from" + checkExists.getAbsolutePath() + " 100 times , please set java.io.tempdir" + " to a writable directory");
}
x = ran.nextInt(1000000);
f = new File(s, "camel-tmp-" + x);
}
return f;
}
use of java.util.Random in project camel by apache.
the class AbstractGoogleCalendarTestSupport method createTestCalendar.
@Before
public void createTestCalendar() {
Calendar calendar = new Calendar();
Random rand = new Random();
calendar.setSummary("camel-calendar-" + rand.nextInt());
calendar.setTimeZone("America/St_Johns");
this.calendar = requestBody("google-calendar://calendars/insert?inBody=content", calendar);
}
use of java.util.Random in project flink by apache.
the class LargeRecordsTest method testHandleMixedLargeRecords.
@Test
public void testHandleMixedLargeRecords() {
try {
final int NUM_RECORDS = 99;
final int SEGMENT_SIZE = 32 * 1024;
final RecordSerializer<SerializationTestType> serializer = new SpanningRecordSerializer<SerializationTestType>();
final RecordDeserializer<SerializationTestType> deserializer = new AdaptiveSpanningRecordDeserializer<SerializationTestType>();
final Buffer buffer = new Buffer(MemorySegmentFactory.allocateUnpooledSegment(SEGMENT_SIZE), mock(BufferRecycler.class));
List<SerializationTestType> originalRecords = new ArrayList<SerializationTestType>((NUM_RECORDS + 1) / 2);
List<SerializationTestType> deserializedRecords = new ArrayList<SerializationTestType>((NUM_RECORDS + 1) / 2);
LargeObjectType genLarge = new LargeObjectType();
Random rnd = new Random();
for (int i = 0; i < NUM_RECORDS; i++) {
if (i % 2 == 0) {
originalRecords.add(new IntType(42));
deserializedRecords.add(new IntType());
} else {
originalRecords.add(genLarge.getRandom(rnd));
deserializedRecords.add(new LargeObjectType());
}
}
// -------------------------------------------------------------------------------------------------------------
serializer.setNextBuffer(buffer);
int numRecordsDeserialized = 0;
for (SerializationTestType record : originalRecords) {
// serialize record
if (serializer.addRecord(record).isFullBuffer()) {
// buffer is full => move to deserializer
deserializer.setNextMemorySegment(serializer.getCurrentBuffer().getMemorySegment(), SEGMENT_SIZE);
// deserialize records, as many complete as there are
while (numRecordsDeserialized < deserializedRecords.size()) {
SerializationTestType next = deserializedRecords.get(numRecordsDeserialized);
if (deserializer.getNextRecord(next).isFullRecord()) {
assertEquals(originalRecords.get(numRecordsDeserialized), next);
numRecordsDeserialized++;
} else {
break;
}
}
// move buffers as long as necessary (for long records)
while (serializer.setNextBuffer(buffer).isFullBuffer()) {
deserializer.setNextMemorySegment(serializer.getCurrentBuffer().getMemorySegment(), SEGMENT_SIZE);
}
// deserialize records, as many as there are in the last buffer
while (numRecordsDeserialized < deserializedRecords.size()) {
SerializationTestType next = deserializedRecords.get(numRecordsDeserialized);
if (deserializer.getNextRecord(next).isFullRecord()) {
assertEquals(originalRecords.get(numRecordsDeserialized), next);
numRecordsDeserialized++;
} else {
break;
}
}
}
}
// move the last (incomplete buffer)
Buffer last = serializer.getCurrentBuffer();
deserializer.setNextMemorySegment(last.getMemorySegment(), last.getSize());
serializer.clear();
// deserialize records, as many as there are in the last buffer
while (numRecordsDeserialized < deserializedRecords.size()) {
SerializationTestType next = deserializedRecords.get(numRecordsDeserialized);
assertTrue(deserializer.getNextRecord(next).isFullRecord());
assertEquals(originalRecords.get(numRecordsDeserialized), next);
numRecordsDeserialized++;
}
// might be that the last big records has not yet been fully moved, and a small one is missing
assertFalse(serializer.hasData());
assertFalse(deserializer.hasUnfinishedData());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations