PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/v3.2/nimbits-sdk/test/ShardTest.java

http://nimbits-server.googlecode.com/
Java | 87 lines | 50 code | 19 blank | 18 comment | 4 complexity | 7cc66979cf69277b3ef968122dbb2c9c MD5 | raw file
 1/*
 2 * Copyright (c) 2010 Tonic Solutions LLC.
 3 *
 4 * http://www.nimbits.com
 5 *
 6 *
 7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 8 *
 9 * http://www.gnu.org/licenses/gpl.html
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
12 */
13
14import com.nimbits.client.model.category.CategoryName;
15import com.nimbits.client.model.common.CommonFactoryLocator;
16import com.nimbits.client.model.point.Point;
17import com.nimbits.client.model.point.PointName;
18import com.nimbits.client.model.value.Value;
19import org.junit.Test;
20
21import java.io.UnsupportedEncodingException;
22import java.util.List;
23import java.util.UUID;
24
25import static org.junit.Assert.*;
26
27/**
28 * Created by bsautner
29 * User: benjamin
30 * Date: 10/12/11
31 * Time: 11:32 AM
32 */
33public class ShardTest {
34
35    @Test
36    public void testShard() throws UnsupportedEncodingException, InterruptedException {
37
38        CategoryName categoryName = CommonFactoryLocator.getInstance().createCategoryName(UUID.randomUUID().toString());
39        PointName pointName = CommonFactoryLocator.getInstance().createPointName(UUID.randomUUID().toString());
40        Common.authOnQA().addCategory(categoryName);
41        Point point = Common.authOnQA().addPoint(categoryName, pointName);
42        assertNotNull(point);
43        assertTrue(point.getId() > 0);
44        assertTrue(point.getHighestRecordedValue() == 0);
45        Thread.sleep(3000);
46        int count = 100;
47
48
49        for (int run = 0; run < 10; run++) {
50            StringBuilder builder = new StringBuilder();
51            double r = 0.0;
52            for (int i = 0; i < count; i++) {
53
54                builder.append("p").append(i).append("=").append(pointName.getValue()).append("&");
55                builder.append("v").append(i).append("=").append(i).append("&");
56                r += i;
57            }
58
59            String param = builder.toString().substring(0, builder.toString().length() - 1);
60
61            System.out.println(param);
62
63            Common.authOnQA().recordBatch(param);
64
65            Thread.sleep(1000);
66
67            Thread.sleep(5000);
68            List<Value> values = Common.authOnQA().getSeries(pointName, count);
69            double d = 0.0;
70
71            for (Value v : values) {
72                d += v.getValue();
73                System.out.println(v.getValue());
74            }
75            Point result = Common.authOnQA().getPoint(pointName);
76            assertEquals(result.getHighestRecordedValue(), Double.valueOf(count - 1), 0);
77
78            assertEquals(r, d, 0.0);
79            Thread.sleep(2000);
80            System.out.println(d);
81        }
82        Common.authOnQA().deleteCategory(categoryName);
83
84
85    }
86
87}