List of usage examples for java.lang Double longValue
public long longValue()
From source file:org.apache.solr.client.solrj.io.stream.StreamExpressionTest.java
@Test public void testDaemonStream() throws Exception { new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1") .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2") .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3") .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4") .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5") .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6") .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7") .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8") .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9") .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10") .commit(cluster.getSolrClient(), COLLECTIONORALIAS); StreamFactory factory = new StreamFactory() .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress()) .withFunctionName("search", CloudSolrStream.class).withFunctionName("rollup", RollupStream.class) .withFunctionName("sum", SumMetric.class).withFunctionName("min", MinMetric.class) .withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class) .withFunctionName("count", CountMetric.class).withFunctionName("daemon", DaemonStream.class); StreamExpression expression;//from w w w.j a v a 2 s . co m DaemonStream daemonStream; expression = StreamExpressionParser.parse( "daemon(rollup(" + "search(" + COLLECTIONORALIAS + ", q=\"*:*\", fl=\"a_i,a_s\", sort=\"a_s asc\")," + "over=\"a_s\"," + "sum(a_i)" + "), id=\"test\", runInterval=\"1000\", queueSize=\"9\")"); daemonStream = (DaemonStream) factory.constructStream(expression); StreamContext streamContext = new StreamContext(); SolrClientCache solrClientCache = new SolrClientCache(); streamContext.setSolrClientCache(solrClientCache); daemonStream.setStreamContext(streamContext); try { //Test Long and Double Sums daemonStream.open(); // This will start the daemon thread for (int i = 0; i < 4; i++) { Tuple tuple = daemonStream.read(); // Reads from the queue String bucket = tuple.getString("a_s"); Double sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 1:"+bucket); assertTrue(bucket.equals("hello0")); assertTrue(sumi.doubleValue() == 17.0D); tuple = daemonStream.read(); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 2:"+bucket); assertTrue(bucket.equals("hello3")); assertTrue(sumi.doubleValue() == 38.0D); tuple = daemonStream.read(); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 3:"+bucket); assertTrue(bucket.equals("hello4")); assertTrue(sumi.longValue() == 15); } //Now lets wait until the internal queue fills up while (daemonStream.remainingCapacity() > 0) { try { Thread.sleep(1000); } catch (Exception e) { } } //OK capacity is full, let's index a new doc new UpdateRequest().add(id, "10", "a_s", "hello0", "a_i", "1", "a_f", "10") .commit(cluster.getSolrClient(), COLLECTIONORALIAS); //Now lets clear the existing docs in the queue 9, plus 3 more to get passed the run that was blocked. The next run should //have the tuples with the updated count. for (int i = 0; i < 12; i++) { daemonStream.read(); } //And rerun the loop. It should have a new count for hello0 for (int i = 0; i < 4; i++) { Tuple tuple = daemonStream.read(); // Reads from the queue String bucket = tuple.getString("a_s"); Double sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 1:"+bucket); assertTrue(bucket.equals("hello0")); assertTrue(sumi.doubleValue() == 18.0D); tuple = daemonStream.read(); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 2:"+bucket); assertTrue(bucket.equals("hello3")); assertTrue(sumi.doubleValue() == 38.0D); tuple = daemonStream.read(); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); //System.out.println("#################################### Bucket 3:"+bucket); assertTrue(bucket.equals("hello4")); assertTrue(sumi.longValue() == 15); } } finally { daemonStream.close(); //This should stop the daemon thread solrClientCache.close(); } }
From source file:org.apache.solr.client.solrj.io.stream.StreamExpressionTest.java
@Test public void testRollupStream() throws Exception { new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1") .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2") .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3") .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4") .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5") .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6") .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7") .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8") .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9") .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10") .commit(cluster.getSolrClient(), COLLECTIONORALIAS); StreamFactory factory = new StreamFactory() .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress()) .withFunctionName("search", CloudSolrStream.class).withFunctionName("rollup", RollupStream.class) .withFunctionName("sum", SumMetric.class).withFunctionName("min", MinMetric.class) .withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class) .withFunctionName("count", CountMetric.class); StreamExpression expression;/*from w w w . j av a 2 s . co m*/ TupleStream stream; List<Tuple> tuples; StreamContext streamContext = new StreamContext(); SolrClientCache solrClientCache = new SolrClientCache(); streamContext.setSolrClientCache(solrClientCache); try { expression = StreamExpressionParser.parse( "rollup(" + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\")," + "over=\"a_s\"," + "sum(a_i)," + "sum(a_f)," + "min(a_i)," + "min(a_f)," + "max(a_i)," + "max(a_f)," + "avg(a_i)," + "avg(a_f)," + "count(*)," + ")"); stream = factory.constructStream(expression); stream.setStreamContext(streamContext); tuples = getTuples(stream); assert (tuples.size() == 3); //Test Long and Double Sums Tuple tuple = tuples.get(0); String bucket = tuple.getString("a_s"); Double sumi = tuple.getDouble("sum(a_i)"); Double sumf = tuple.getDouble("sum(a_f)"); Double mini = tuple.getDouble("min(a_i)"); Double minf = tuple.getDouble("min(a_f)"); Double maxi = tuple.getDouble("max(a_i)"); Double maxf = tuple.getDouble("max(a_f)"); Double avgi = tuple.getDouble("avg(a_i)"); Double avgf = tuple.getDouble("avg(a_f)"); Double count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello0")); assertTrue(sumi.doubleValue() == 17.0D); assertTrue(sumf.doubleValue() == 18.0D); assertTrue(mini.doubleValue() == 0.0D); assertTrue(minf.doubleValue() == 1.0D); assertTrue(maxi.doubleValue() == 14.0D); assertTrue(maxf.doubleValue() == 10.0D); assertTrue(avgi.doubleValue() == 4.25D); assertTrue(avgf.doubleValue() == 4.5D); assertTrue(count.doubleValue() == 4); tuple = tuples.get(1); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); sumf = tuple.getDouble("sum(a_f)"); mini = tuple.getDouble("min(a_i)"); minf = tuple.getDouble("min(a_f)"); maxi = tuple.getDouble("max(a_i)"); maxf = tuple.getDouble("max(a_f)"); avgi = tuple.getDouble("avg(a_i)"); avgf = tuple.getDouble("avg(a_f)"); count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello3")); assertTrue(sumi.doubleValue() == 38.0D); assertTrue(sumf.doubleValue() == 26.0D); assertTrue(mini.doubleValue() == 3.0D); assertTrue(minf.doubleValue() == 3.0D); assertTrue(maxi.doubleValue() == 13.0D); assertTrue(maxf.doubleValue() == 9.0D); assertTrue(avgi.doubleValue() == 9.5D); assertTrue(avgf.doubleValue() == 6.5D); assertTrue(count.doubleValue() == 4); tuple = tuples.get(2); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); sumf = tuple.getDouble("sum(a_f)"); mini = tuple.getDouble("min(a_i)"); minf = tuple.getDouble("min(a_f)"); maxi = tuple.getDouble("max(a_i)"); maxf = tuple.getDouble("max(a_f)"); avgi = tuple.getDouble("avg(a_i)"); avgf = tuple.getDouble("avg(a_f)"); count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello4")); assertTrue(sumi.longValue() == 15); assertTrue(sumf.doubleValue() == 11.0D); assertTrue(mini.doubleValue() == 4.0D); assertTrue(minf.doubleValue() == 4.0D); assertTrue(maxi.doubleValue() == 11.0D); assertTrue(maxf.doubleValue() == 7.0D); assertTrue(avgi.doubleValue() == 7.5D); assertTrue(avgf.doubleValue() == 5.5D); assertTrue(count.doubleValue() == 2); } finally { solrClientCache.close(); } }
From source file:org.apache.solr.client.solrj.io.stream.StreamExpressionTest.java
@Test public void testParallelRollupStream() throws Exception { new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1") .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2") .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3") .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4") .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5") .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6") .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7") .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8") .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9") .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10") .commit(cluster.getSolrClient(), COLLECTIONORALIAS); StreamFactory factory = new StreamFactory() .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress()) .withFunctionName("search", CloudSolrStream.class) .withFunctionName("parallel", ParallelStream.class).withFunctionName("rollup", RollupStream.class) .withFunctionName("sum", SumMetric.class).withFunctionName("min", MinMetric.class) .withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class) .withFunctionName("count", CountMetric.class); StreamContext streamContext = new StreamContext(); SolrClientCache solrClientCache = new SolrClientCache(); streamContext.setSolrClientCache(solrClientCache); StreamExpression expression;/*www. j a va 2 s .c o m*/ TupleStream stream; List<Tuple> tuples; try { expression = StreamExpressionParser.parse("parallel(" + COLLECTIONORALIAS + "," + "rollup(" + "search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"a_s,a_i,a_f\", sort=\"a_s asc\", partitionKeys=\"a_s\")," + "over=\"a_s\"," + "sum(a_i)," + "sum(a_f)," + "min(a_i)," + "min(a_f)," + "max(a_i)," + "max(a_f)," + "avg(a_i)," + "avg(a_f)," + "count(*)" + ")," + "workers=\"2\", zkHost=\"" + cluster.getZkServer().getZkAddress() + "\", sort=\"a_s asc\")"); stream = factory.constructStream(expression); stream.setStreamContext(streamContext); tuples = getTuples(stream); assert (tuples.size() == 3); //Test Long and Double Sums Tuple tuple = tuples.get(0); String bucket = tuple.getString("a_s"); Double sumi = tuple.getDouble("sum(a_i)"); Double sumf = tuple.getDouble("sum(a_f)"); Double mini = tuple.getDouble("min(a_i)"); Double minf = tuple.getDouble("min(a_f)"); Double maxi = tuple.getDouble("max(a_i)"); Double maxf = tuple.getDouble("max(a_f)"); Double avgi = tuple.getDouble("avg(a_i)"); Double avgf = tuple.getDouble("avg(a_f)"); Double count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello0")); assertTrue(sumi.doubleValue() == 17.0D); assertTrue(sumf.doubleValue() == 18.0D); assertTrue(mini.doubleValue() == 0.0D); assertTrue(minf.doubleValue() == 1.0D); assertTrue(maxi.doubleValue() == 14.0D); assertTrue(maxf.doubleValue() == 10.0D); assertTrue(avgi.doubleValue() == 4.25D); assertTrue(avgf.doubleValue() == 4.5D); assertTrue(count.doubleValue() == 4); tuple = tuples.get(1); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); sumf = tuple.getDouble("sum(a_f)"); mini = tuple.getDouble("min(a_i)"); minf = tuple.getDouble("min(a_f)"); maxi = tuple.getDouble("max(a_i)"); maxf = tuple.getDouble("max(a_f)"); avgi = tuple.getDouble("avg(a_i)"); avgf = tuple.getDouble("avg(a_f)"); count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello3")); assertTrue(sumi.doubleValue() == 38.0D); assertTrue(sumf.doubleValue() == 26.0D); assertTrue(mini.doubleValue() == 3.0D); assertTrue(minf.doubleValue() == 3.0D); assertTrue(maxi.doubleValue() == 13.0D); assertTrue(maxf.doubleValue() == 9.0D); assertTrue(avgi.doubleValue() == 9.5D); assertTrue(avgf.doubleValue() == 6.5D); assertTrue(count.doubleValue() == 4); tuple = tuples.get(2); bucket = tuple.getString("a_s"); sumi = tuple.getDouble("sum(a_i)"); sumf = tuple.getDouble("sum(a_f)"); mini = tuple.getDouble("min(a_i)"); minf = tuple.getDouble("min(a_f)"); maxi = tuple.getDouble("max(a_i)"); maxf = tuple.getDouble("max(a_f)"); avgi = tuple.getDouble("avg(a_i)"); avgf = tuple.getDouble("avg(a_f)"); count = tuple.getDouble("count(*)"); assertTrue(bucket.equals("hello4")); assertTrue(sumi.longValue() == 15); assertTrue(sumf.doubleValue() == 11.0D); assertTrue(mini.doubleValue() == 4.0D); assertTrue(minf.doubleValue() == 4.0D); assertTrue(maxi.doubleValue() == 11.0D); assertTrue(maxf.doubleValue() == 7.0D); assertTrue(avgi.doubleValue() == 7.5D); assertTrue(avgf.doubleValue() == 5.5D); assertTrue(count.doubleValue() == 2); } finally { solrClientCache.close(); } }