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

http://nimbits-server.googlecode.com/ · Java · 119 lines · 78 code · 28 blank · 13 comment · 5 complexity · 4edb79e93f899f228e9aa28c3f1fd43d MD5 · raw file

  1. /*
  2. * Copyright (c) 2011. Tonic Solutions LLC. All Rights reserved.
  3. *
  4. * This source code is distributed under GPL v3 without any warranty.
  5. */
  6. import com.nimbits.client.NimbitsClient;
  7. import com.nimbits.client.NimbitsClientFactory;
  8. import com.nimbits.client.model.common.CommonFactoryLocator;
  9. import com.nimbits.client.model.email.EmailAddress;
  10. import com.nimbits.client.model.point.PointName;
  11. import com.nimbits.client.model.value.Value;
  12. import com.nimbits.user.NimbitsUser;
  13. import com.nimbits.user.UserFactory;
  14. import org.junit.Test;
  15. import java.io.IOException;
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.Random;
  19. import static java.lang.Thread.sleep;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.junit.Assert.assertNotNull;
  22. /**
  23. * Created by bsautner
  24. * User: benjamin
  25. * Date: 3/27/11
  26. * Time: 3:08 PM
  27. */
  28. public class DataLoadingTest {
  29. private void sample() {
  30. EmailAddress emailAddress = CommonFactoryLocator.getInstance().createEmailAddress("test@example.com");
  31. NimbitsUser user = UserFactory.createNimbitsUser(emailAddress, "pas$$word");
  32. NimbitsClient client = NimbitsClientFactory.getInstance(user, "http://mynimbitsserver.domain.com");
  33. PointName pointName = CommonFactoryLocator.getInstance().createPointName("MyDataPoint");
  34. Value currentValue = client.getCurrentRecordedValue(pointName);
  35. System.out.println(currentValue.getValue()); //get the last recorded double value
  36. System.out.println(currentValue.getAlertState().name()); //the state of the point - i.e high alert or idle
  37. }
  38. @Test
  39. public void TempFTestOnProd() throws InterruptedException, IOException {
  40. PointName pointName = CommonFactoryLocator.getInstance().createPointName("TempF");
  41. for (int i = 0; i < 10; i++) {
  42. Common.meOnProd().recordValueWithGet(pointName, i, new Date());
  43. sleep(1000);
  44. }
  45. sleep(2000);
  46. List<Value> result = Common.meOnProd().getSeries(pointName, 10);
  47. double t = 0;
  48. for (Value v : result) {
  49. System.out.println(v.getValue());
  50. t += v.getValue();
  51. }
  52. System.out.println(t);
  53. assertEquals(45.0, t, 0);
  54. }
  55. @Test
  56. public void TempNewPointOnProd() throws InterruptedException, IOException {
  57. PointName pointName = CommonFactoryLocator.getInstance().createPointName("new");
  58. System.out.println(Common.meOnProd().isLoggedIn());
  59. for (int i = 0; i < 10; i++) {
  60. Common.meOnProd().recordValue(pointName, i, new Date());
  61. sleep(1000);
  62. }
  63. sleep(2000);
  64. List<Value> result = Common.meOnProd().getSeries(pointName, 10);
  65. for (Value v : result) {
  66. System.out.println(v.getValue());
  67. }
  68. }
  69. @Test
  70. public void testLoadRandom() throws IOException {
  71. Date start = new Date();
  72. Random r = new Random();
  73. for (int i = 0; i < 10; i++) {
  74. try {
  75. System.out.println(i);
  76. PointName pointName = CommonFactoryLocator.getInstance().createPointName("b1");
  77. Value v = Common.client().recordValue(pointName, (r.nextDouble() * 100), new Date());
  78. assertNotNull(v);
  79. // Assert.assertTrue(v.getKey() > 0);
  80. // Thread.sleep(100);
  81. } catch (Exception ex) {
  82. ex.printStackTrace();
  83. }
  84. }
  85. Date end = new Date();
  86. long time = (end.getTime() - start.getTime()) / 1000;
  87. System.out.println(time);
  88. PointName pointName = CommonFactoryLocator.getInstance().createPointName("Time to record 10 values to b1");
  89. Common.clientSupportOnProd().recordValue(pointName, time, new Date());
  90. }
  91. }