/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. import com.nimbits.client.model.category.CategoryName;
  14. import com.nimbits.client.model.common.CommonFactoryLocator;
  15. import com.nimbits.client.model.point.Point;
  16. import com.nimbits.client.model.point.PointName;
  17. import com.nimbits.client.model.value.Value;
  18. import org.junit.Test;
  19. import java.io.UnsupportedEncodingException;
  20. import java.util.List;
  21. import java.util.UUID;
  22. import static org.junit.Assert.*;
  23. /**
  24. * Created by bsautner
  25. * User: benjamin
  26. * Date: 10/12/11
  27. * Time: 11:32 AM
  28. */
  29. public class ShardTest {
  30. @Test
  31. public void testShard() throws UnsupportedEncodingException, InterruptedException {
  32. CategoryName categoryName = CommonFactoryLocator.getInstance().createCategoryName(UUID.randomUUID().toString());
  33. PointName pointName = CommonFactoryLocator.getInstance().createPointName(UUID.randomUUID().toString());
  34. Common.authOnQA().addCategory(categoryName);
  35. Point point = Common.authOnQA().addPoint(categoryName, pointName);
  36. assertNotNull(point);
  37. assertTrue(point.getId() > 0);
  38. assertTrue(point.getHighestRecordedValue() == 0);
  39. Thread.sleep(3000);
  40. int count = 100;
  41. for (int run = 0; run < 10; run++) {
  42. StringBuilder builder = new StringBuilder();
  43. double r = 0.0;
  44. for (int i = 0; i < count; i++) {
  45. builder.append("p").append(i).append("=").append(pointName.getValue()).append("&");
  46. builder.append("v").append(i).append("=").append(i).append("&");
  47. r += i;
  48. }
  49. String param = builder.toString().substring(0, builder.toString().length() - 1);
  50. System.out.println(param);
  51. Common.authOnQA().recordBatch(param);
  52. Thread.sleep(1000);
  53. Thread.sleep(5000);
  54. List<Value> values = Common.authOnQA().getSeries(pointName, count);
  55. double d = 0.0;
  56. for (Value v : values) {
  57. d += v.getValue();
  58. System.out.println(v.getValue());
  59. }
  60. Point result = Common.authOnQA().getPoint(pointName);
  61. assertEquals(result.getHighestRecordedValue(), Double.valueOf(count - 1), 0);
  62. assertEquals(r, d, 0.0);
  63. Thread.sleep(2000);
  64. System.out.println(d);
  65. }
  66. Common.authOnQA().deleteCategory(categoryName);
  67. }
  68. }