List of usage examples for java.util Random nextBoolean
public boolean nextBoolean()
From source file:org.elasticsearch.test.ElasticsearchIntegrationTest.java
private static Settings.Builder setRandomNormsLoading(Random random, Settings.Builder builder) { if (random.nextBoolean()) { builder.put(SearchService.NORMS_LOADING_KEY, RandomPicks.randomFrom(random, Arrays.asList(MappedFieldType.Loading.EAGER, MappedFieldType.Loading.LAZY))); }//from w w w . j a v a2 s. c o m return builder; }
From source file:org.elasticsearch.test.ElasticsearchIntegrationTest.java
private static Settings.Builder setRandomScriptingSettings(Random random, Settings.Builder builder) { if (random.nextBoolean()) { builder.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING, RandomInts.randomIntBetween(random, -100, 2000)); }//from w w w. j av a 2 s. c om if (random.nextBoolean()) { builder.put(ScriptService.SCRIPT_CACHE_EXPIRE_SETTING, TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 750, 10000000))); } return builder; }
From source file:org.elasticsearch.test.ElasticsearchIntegrationTest.java
private static Settings.Builder setRandomMerge(Random random, Settings.Builder builder) { if (random.nextBoolean()) { builder.put(MergePolicyConfig.INDEX_COMPOUND_FORMAT, random.nextBoolean() ? random.nextDouble() : random.nextBoolean()); }//from w w w . j a v a 2 s. co m switch (random.nextInt(4)) { case 3: final int maxThreadCount = RandomInts.randomIntBetween(random, 1, 4); final int maxMergeCount = RandomInts.randomIntBetween(random, maxThreadCount, maxThreadCount + 4); builder.put(MergeSchedulerConfig.MAX_MERGE_COUNT, maxMergeCount); builder.put(MergeSchedulerConfig.MAX_THREAD_COUNT, maxThreadCount); break; } return builder; }
From source file:net.bull.javamelody.TestMonitoringFilter.java
private void monitoring(Map<HttpParameter, String> parameters, boolean checkResultContent) throws IOException, ServletException { final HttpServletRequest request = createNiceMock(HttpServletRequest.class); expect(request.getRequestURI()).andReturn("/test/monitoring").anyTimes(); expect(request.getRequestURL()).andReturn(new StringBuffer("/test/monitoring")).anyTimes(); expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes(); expect(request.getRemoteAddr()).andReturn("here").anyTimes(); final Random random = new Random(); if (random.nextBoolean()) { expect(request.getHeaders("Accept-Encoding")) .andReturn(Collections.enumeration(Arrays.asList("application/gzip"))).anyTimes(); } else {//from ww w. j a v a 2 s . c o m expect(request.getHeaders("Accept-Encoding")) .andReturn(Collections.enumeration(Arrays.asList("text/html"))).anyTimes(); } for (final Map.Entry<HttpParameter, String> entry : parameters.entrySet()) { if (HttpParameter.REQUEST == entry.getKey()) { expect(request.getHeader(entry.getKey().getName())).andReturn(entry.getValue()).anyTimes(); } else { expect(entry.getKey().getParameterFrom(request)).andReturn(entry.getValue()).anyTimes(); } } final Range range = Period.JOUR.getRange(); final List<JavaInformations> javaInformationsList = Collections .singletonList(new JavaInformations(null, false)); // getAttribute("range") et getAttribute("javaInformationsList") pour PdfController expect(request.getAttribute("range")).andReturn(range).anyTimes(); expect(request.getAttribute("javaInformationsList")).andReturn(javaInformationsList).anyTimes(); if (parameters.isEmpty() || HttpPart.JNLP.getName().equals(parameters.get(HttpParameter.PART))) { // dans au moins un cas on met un cookie final Cookie[] cookies = { new Cookie("dummy", "dummy"), new Cookie(PERIOD_COOKIE_NAME, Period.SEMAINE.getCode()), }; expect(request.getCookies()).andReturn(cookies).anyTimes(); } final HttpServletResponse response = createNiceMock(HttpServletResponse.class); final ByteArrayOutputStream output = new ByteArrayOutputStream(); expect(response.getOutputStream()).andReturn(new FilterServletOutputStream(output)).anyTimes(); final StringWriter stringWriter = new StringWriter(); expect(response.getWriter()).andReturn(new PrintWriter(stringWriter)).anyTimes(); final FilterChain chain = createNiceMock(FilterChain.class); replay(request); replay(response); replay(chain); monitoringFilter.doFilter(request, response, chain); verify(request); verify(response); verify(chain); if (checkResultContent) { assertTrue("result", output.size() != 0 || stringWriter.getBuffer().length() != 0); } }
From source file:org.elasticsearch.test.ElasticsearchIntegrationTest.java
private static Settings.Builder setRandomTranslogSettings(Random random, Settings.Builder builder) { if (random.nextBoolean()) { builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, RandomInts.randomIntBetween(random, 1, 10000)); }//from w ww. ja v a2 s.co m if (random.nextBoolean()) { builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(RandomInts.randomIntBetween(random, 1, 300), ByteSizeUnit.MB)); } if (random.nextBoolean()) { builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, TimeValue.timeValueMinutes(RandomInts.randomIntBetween(random, 1, 60))); } if (random.nextBoolean()) { builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_INTERVAL, TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 1, 10000))); } if (random.nextBoolean()) { builder.put(TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH, random.nextBoolean()); } if (random.nextBoolean()) { builder.put(TranslogConfig.INDEX_TRANSLOG_DURABILITY, RandomPicks.randomFrom(random, Translog.Durabilty.values())); } return builder; }
From source file:org.activiti.rest.demo.DemoDataGenerator.java
protected void initDemoStandaloneTasks() { List<User> users = identityService.createUserQuery().list(); List<Group> groups = identityService.createGroupQuery().groupType("assignment").list(); Random random = new Random(); String loremIpsum = "Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et " + "dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat" + " Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat " + "cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum"; String[] words = loremIpsum.split(" "); for (int i = 0; i < 100; i++) { Task task = taskService.newTask(); task.setName(randomSentence(words, 6)); task.setDescription(randomSentence(words, 15)); taskService.saveTask(task);/*from www .j av a2 s .c o m*/ if (random.nextBoolean()) { taskService.setAssignee(task.getId(), users.get(random.nextInt(users.size())).getId()); } else { taskService.addCandidateGroup(task.getId(), groups.get(random.nextInt(groups.size())).getId()); } } }
From source file:io.prestosql.execution.resourceGroups.TestResourceGroups.java
@Test(timeOut = 10_000) public void testPriorityScheduling() { RootInternalResourceGroup root = new RootInternalResourceGroup("root", (group, export) -> { }, directExecutor());//from w w w .ja v a2 s . co m root.setSoftMemoryLimit(new DataSize(1, MEGABYTE)); root.setMaxQueuedQueries(100); // Start with zero capacity, so that nothing starts running until we've added all the queries root.setHardConcurrencyLimit(0); root.setSchedulingPolicy(QUERY_PRIORITY); InternalResourceGroup group1 = root.getOrCreateSubGroup("1"); group1.setSoftMemoryLimit(new DataSize(1, MEGABYTE)); group1.setMaxQueuedQueries(100); group1.setHardConcurrencyLimit(1); InternalResourceGroup group2 = root.getOrCreateSubGroup("2"); group2.setSoftMemoryLimit(new DataSize(1, MEGABYTE)); group2.setMaxQueuedQueries(100); group2.setHardConcurrencyLimit(1); SortedMap<Integer, MockQueryExecution> queries = new TreeMap<>(); Random random = new Random(); for (int i = 0; i < 100; i++) { int priority; do { priority = random.nextInt(1_000_000) + 1; } while (queries.containsKey(priority)); MockQueryExecution query = new MockQueryExecution(0, "query_id", priority); if (random.nextBoolean()) { group1.run(query); } else { group2.run(query); } queries.put(priority, query); } root.setHardConcurrencyLimit(1); List<MockQueryExecution> orderedQueries = new ArrayList<>(queries.values()); reverse(orderedQueries); for (MockQueryExecution query : orderedQueries) { root.processQueuedQueries(); assertEquals(query.getState(), RUNNING); query.complete(); } }
From source file:org.rapidandroid.tests.ContentBootstrapTests.java
public void test006InsertDummyFormData() { test005RegenerateTablesForForms();//from w ww . jav a 2 s . c o m Uri query = RapidSmsDBConstants.Form.CONTENT_URI; Cursor cr = getContext().getContentResolver().query(query, null, null, null, null); cr.moveToFirst(); do { int id = cr.getInt(0); // presumably the id Uri directUri = Uri.parse(RapidSmsDBConstants.Form.CONTENT_URI_STRING + id); Form f = ModelTranslator.getFormFromUri(directUri); for (int msgcount = 0; msgcount < 10; msgcount++) { // first, let's make a new dummy message: // doSendMessage("test message " + msgcount, "10/31/2008 11:0" // + msgcount, "6176453236"); // String msgid = currUri.getPathSegments().get(1); String msgid = "1"; ContentValues cv = new ContentValues(); cv.put(RapidSmsDBConstants.FormData.MESSAGE, msgid); Field[] fields = f.getFields(); int len = fields.length; Random r = new Random(); for (int i = 0; i < len; i++) { Field field = fields[i]; if (field.getFieldType().getParsedDataType().equals("integer")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), r.nextInt(10000)); } else if (field.getFieldType().getParsedDataType().equals("number")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), r.nextInt(10000)); } else if (field.getFieldType().getParsedDataType().equals("boolean")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), r.nextBoolean()); } else if (field.getFieldType().getParsedDataType().equals("word")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), Math.random() + ""); } else if (field.getFieldType().getParsedDataType().equals("ratio")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), Math.random() + ""); } else if (field.getFieldType().getParsedDataType().equals("datetime")) { cv.put(RapidSmsDBConstants.FormData.COLUMN_PREFIX + field.getName(), "10/31/2008 11:59"); } } Uri inserted = getContext().getContentResolver() .insert(Uri.parse(RapidSmsDBConstants.FormData.CONTENT_URI_PREFIX + f.getFormId()), cv); Log.d("dimagi", "inserted form data for: " + inserted); } } while (cr.moveToNext()); cr.close(); }
From source file:org.apache.tinkerpop.gremlin.structure.TransactionTest.java
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = FEATURE_DOUBLE_VALUES) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES) @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES) @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_INTEGER_VALUES) public void shouldExecuteWithCompetingThreads() { int totalThreads = 250; final AtomicInteger vertices = new AtomicInteger(0); final AtomicInteger edges = new AtomicInteger(0); final AtomicInteger completedThreads = new AtomicInteger(0); for (int i = 0; i < totalThreads; i++) { new Thread() { @Override/*from w w w.j av a 2 s .c om*/ public void run() { final Random random = new Random(); if (random.nextBoolean()) { final Vertex a = graph.addVertex(); final Vertex b = graph.addVertex(); final Edge e = a.addEdge("friend", b); vertices.getAndAdd(2); a.property(VertexProperty.Cardinality.single, "test", this.getId()); b.property(VertexProperty.Cardinality.single, "blah", random.nextDouble()); e.property("bloop", random.nextInt()); edges.getAndAdd(1); graph.tx().commit(); } else { final Vertex a = graph.addVertex(); final Vertex b = graph.addVertex(); final Edge e = a.addEdge("friend", b); a.property(VertexProperty.Cardinality.single, "test", this.getId()); b.property(VertexProperty.Cardinality.single, "blah", random.nextDouble()); e.property("bloop", random.nextInt()); if (random.nextBoolean()) { graph.tx().commit(); vertices.getAndAdd(2); edges.getAndAdd(1); } else { graph.tx().rollback(); } } completedThreads.getAndAdd(1); } }.start(); } while (completedThreads.get() < totalThreads) { } assertEquals(completedThreads.get(), 250); assertVertexEdgeCounts(vertices.get(), edges.get()); }
From source file:org.apache.marmotta.kiwi.test.PersistenceTest.java
/** * Test storing and loading string literals (with type and without language). * * @throws SQLException//from w w w . j a v a2s .co m */ @Test public void testStoreBooleanLiteral() throws SQLException { KiWiConnection connection = persistence.getConnection(); try { KiWiUriResource uri = new KiWiUriResource(Namespaces.NS_XSD + "boolean"); Random rnd = new Random(); boolean value = rnd.nextBoolean(); // add a new URI to the triple store and check if it exists afterwards, before and after commit KiWiBooleanLiteral literal = new KiWiBooleanLiteral(value, uri); connection.storeNode(literal); // check if it then has a database ID Assert.assertTrue(literal.getId() >= 0); KiWiNode testLiteral1 = connection.loadNodeById(literal.getId()); // needs to be equal, and should also be the identical object! Assert.assertEquals(literal, testLiteral1); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral1).getType()); //Assert.assertTrue(literal == testLiteral1); connection.commit(); KiWiNode testLiteral2 = connection.loadNodeById(literal.getId()); // needs to be equal, and should also be the identical object! Assert.assertEquals(literal, testLiteral2); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral2).getType()); //Assert.assertTrue(literal == testLiteral2); KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(), null, uri); // needs to be equal, and should also be the identical object! Assert.assertEquals(literal, testLiteral3); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral3).getType()); //Assert.assertTrue(literal == testLiteral3); // load by integer value KiWiNode testLiteral6 = connection.loadLiteral(value); // needs to be equal, and should also be the identical object! Assert.assertEquals(literal, testLiteral6); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral6).getType()); //Assert.assertTrue(literal == testLiteral6); connection.commit(); // clear cache and test again persistence.clearCache(); KiWiNode testLiteral4 = connection.loadNodeById(literal.getId()); // needs to be equal, but now it should not be the same object! Assert.assertEquals(literal, testLiteral4); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral4).getType()); //Assert.assertTrue(literal != testLiteral4); KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(), null, uri); // needs to be equal, but now it should not be the same object! Assert.assertEquals(literal, testLiteral5); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral5).getType()); //Assert.assertTrue(literal != testLiteral5); // load by integer value KiWiNode testLiteral7 = connection.loadLiteral(value); // needs to be equal, and should also be the identical object! Assert.assertEquals(literal, testLiteral7); Assert.assertEquals(uri, ((KiWiLiteral) testLiteral7).getType()); //Assert.assertTrue(literal != testLiteral7); connection.commit(); // finally do a test on the nodes table, it should contain exactly one entry PreparedStatement checkNodeStmt = connection.getJDBCConnection() .prepareStatement("SELECT * FROM nodes WHERE ntype='boolean'"); ResultSet result = checkNodeStmt.executeQuery(); Assert.assertTrue(result.next()); Assert.assertEquals((long) literal.getId(), result.getLong("id")); Assert.assertEquals(literal.stringValue(), result.getString("svalue")); Assert.assertEquals(value, result.getBoolean("bvalue")); Assert.assertEquals("boolean", result.getString("ntype")); Assert.assertNull(result.getString("lang")); Assert.assertEquals((long) uri.getId(), result.getLong("ltype")); result.close(); connection.commit(); } finally { connection.close(); } }