コード例 #1
0
 /**
  * Verifies blob properties from output, to that sent in during input
  *
  * @param expectedHeaders the expected headers in the response.
  * @param response the {@link HttpResponse} that contains the headers.
  */
 private void verifyBlobProperties(HttpHeaders expectedHeaders, HttpResponse response) {
   assertEquals(
       "Blob size does not match",
       Long.parseLong(expectedHeaders.get(RestUtils.Headers.BLOB_SIZE)),
       Long.parseLong(HttpHeaders.getHeader(response, RestUtils.Headers.BLOB_SIZE)));
   assertEquals(
       RestUtils.Headers.SERVICE_ID + " does not match",
       expectedHeaders.get(RestUtils.Headers.SERVICE_ID),
       HttpHeaders.getHeader(response, RestUtils.Headers.SERVICE_ID));
   assertEquals(
       RestUtils.Headers.PRIVATE + " does not match",
       expectedHeaders.get(RestUtils.Headers.PRIVATE),
       HttpHeaders.getHeader(response, RestUtils.Headers.PRIVATE));
   assertEquals(
       RestUtils.Headers.AMBRY_CONTENT_TYPE + " does not match",
       expectedHeaders.get(RestUtils.Headers.AMBRY_CONTENT_TYPE),
       HttpHeaders.getHeader(response, RestUtils.Headers.AMBRY_CONTENT_TYPE));
   assertTrue(
       "No " + RestUtils.Headers.CREATION_TIME,
       HttpHeaders.getHeader(response, RestUtils.Headers.CREATION_TIME, null) != null);
   if (Long.parseLong(expectedHeaders.get(RestUtils.Headers.TTL)) != Utils.Infinite_Time) {
     assertEquals(
         RestUtils.Headers.TTL + " does not match",
         expectedHeaders.get(RestUtils.Headers.TTL),
         HttpHeaders.getHeader(response, RestUtils.Headers.TTL));
   }
   if (expectedHeaders.contains(RestUtils.Headers.OWNER_ID)) {
     assertEquals(
         RestUtils.Headers.OWNER_ID + " does not match",
         expectedHeaders.get(RestUtils.Headers.OWNER_ID),
         HttpHeaders.getHeader(response, RestUtils.Headers.OWNER_ID));
   }
 }
コード例 #2
0
 @Test
 public void test()
     throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException,
         SQLException {
   JDBC dao = JDBC.getInstance();
   dao.insertToTweet(
       Long.parseLong("111"), "aaaa", 52.1, 2.36, Long.parseLong("454555"), "sdfg", "asdf");
 }
コード例 #3
0
ファイル: RequestValidator.java プロジェクト: pageone/jbosh
  /**
   * The <body/> element of every client request MUST possess a sequential request ID encapsulated
   * via the 'rid' attribute.
   *
   * @param node node to validate
   * @param previous previous node
   */
  private void assertRequestIDSequential(final Node node, final Node previous) {
    String ridStr = node.getBody().getAttribute(Attributes.RID);
    assertNotNull("Request ID attribute not present", ridStr);

    long rid = Long.parseLong(ridStr);
    if (previous != null) {
      String prevRidStr = previous.getBody().getAttribute(Attributes.RID);
      assertNotNull("Previous request ID attribute not present", prevRidStr);
      long prevRid = Long.parseLong(prevRidStr);
      assertEquals("Request ID is not sequential", prevRid + 1, rid);
    }
  }
コード例 #4
0
  @Test
  public void testCloseSessionByNormalUser() throws Exception {
    String sessionIdString = "555";
    String actionString = Action.CloseSession.toString();
    long sessionIdLong = Long.parseLong(sessionIdString);
    when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString);
    when(mockHttpServletRequest.getParameter(ServletUtil.SESSION_ID)).thenReturn(sessionIdString);

    // set AuthenticateOneTimeUser false
    prepareEnterAuthenticateOneTimeUser(false);
    User user = stubbingCheckUser();

    UsersCache userCacheHelper = mock(UsersCache.class);
    mockStatic(UsersCacheFactory.class);
    when(UsersCacheFactory.getInstance()).thenReturn(userCacheHelper);
    doNothing().when(userCacheHelper);
    userCacheHelper.remove(sessionIdLong);

    // RUN...
    defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse);

    verifyNecessaryChecks(actionString);

    verifyStatic(org.mockito.Mockito.times(1));
    ConnectionUtil.checkUser(loginString, password, false);

    PrintWriter writer = mockHttpServletResponse.getWriter();
    writer.flush();
    System.out.println(outStringWriter.toString());
    // ASSERT...
    assertThat(outStringWriter.toString(), is("RESPONSE:" + String.valueOf(sessionIdLong)));
  }
コード例 #5
0
    @Override
    public void initialize() throws EventHubException {
      if (curInitFaults < initFaultCount) {
        curInitFaults++;
        isFault = true;
        throw new EventHubException("Simulate fault in initialize()");
      }

      // after recovery, forget all the faults
      initFaultCount = 0;
      curInitFaults = 0;
      receiveFaultOffset = -1;
      isFault = false;
      isReceiveNull = false;
      curOffset = -1;

      if (lastMessage != null) {
        String tmpOffset = EventHubMessage.parseAmqpMessage(lastMessage).getOffset();
        // make sure filter is updated
        EventHubOffsetFilter tmpFilter = new EventHubOffsetFilter(tmpOffset);
        assertEquals(filter.getFilterString(), tmpFilter.getFilterString());
        // update curOffset
        curOffset = Long.parseLong(tmpOffset);
      }
    }
コード例 #6
0
ファイル: ScriptTest.java プロジェクト: SambaTeam/sambacoinj
  private Script parseScriptString(String string) throws Exception {
    String[] words = string.split("[ \\t\\n]");

    UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream();

    for (String w : words) {
      if (w.equals("")) continue;
      if (w.matches("^-?[0-9]*$")) {
        // Number
        long val = Long.parseLong(w);
        if (val >= -1 && val <= 16) out.write(Script.encodeToOpN((int) val));
        else
          Script.writeBytes(
              out, Utils.reverseBytes(Utils.encodeMPI(BigInteger.valueOf(val), false)));
      } else if (w.matches("^0x[0-9a-fA-F]*$")) {
        // Raw hex data, inserted NOT pushed onto stack:
        out.write(Hex.decode(w.substring(2)));
      } else if (w.length() >= 2 && w.startsWith("'") && w.endsWith("'")) {
        // Single-quoted string, pushed as data. NOTE: this is poor-man's
        // parsing, spaces/tabs/newlines in single-quoted strings won't work.
        Script.writeBytes(out, w.substring(1, w.length() - 1).getBytes(Charset.forName("UTF-8")));
      } else if (ScriptOpCodes.getOpCode(w) != OP_INVALIDOPCODE) {
        // opcode, e.g. OP_ADD or OP_1:
        out.write(ScriptOpCodes.getOpCode(w));
      } else if (w.startsWith("OP_")
          && ScriptOpCodes.getOpCode(w.substring(3)) != OP_INVALIDOPCODE) {
        // opcode, e.g. OP_ADD or OP_1:
        out.write(ScriptOpCodes.getOpCode(w.substring(3)));
      } else {
        throw new RuntimeException("Invalid Data");
      }
    }

    return new Script(out.toByteArray());
  }
コード例 #7
0
  @Before
  public void setUp() throws Exception {
    try {
      FileReader reader = new FileReader("inventory.txt");
      BufferedReader br = new BufferedReader(reader);

      String row = br.readLine();
      while (row != null) {
        String articleinfo[] = row.split(":");

        char barcode[] = articleinfo[0].toCharArray();
        String name = articleinfo[1];
        int amount = Integer.parseInt(articleinfo[2]);
        double price = Double.parseDouble(articleinfo[3]);
        boolean food = Boolean.parseBoolean(articleinfo[4]);

        tempInventory.add(new cashRegisterSystem.inventoryArticle(barcode, name, amount, price));
        row = br.readLine();
      }

      br.close();
    } catch (IOException e) {
      System.out.println("Error" + e.getMessage());
      System.out.println("Error reading File");
    }

    CRS.newItem(Long.parseLong(sBarcode), sArticleName, dPrice, iAmountInventory, isFood);
    CRS.writeInventory();
  }
コード例 #8
0
 /**
  * Gets the blob with blob ID {@code blobId} and verifies that the headers and content match with
  * what is expected.
  *
  * @param blobId the blob ID of the blob to GET.
  * @param range the {@link ByteRange} for the request.
  * @param expectedHeaders the expected headers in the response.
  * @param expectedContent the expected content of the blob.
  * @throws ExecutionException
  * @throws InterruptedException
  */
 private void getBlobAndVerify(
     String blobId, ByteRange range, HttpHeaders expectedHeaders, ByteBuffer expectedContent)
     throws ExecutionException, InterruptedException, RestServiceException {
   HttpHeaders headers = null;
   if (range != null) {
     headers =
         new DefaultHttpHeaders()
             .add(RestUtils.Headers.RANGE, RestTestUtils.getRangeHeaderString(range));
   }
   FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId, headers, null);
   Queue<HttpObject> responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
   HttpResponse response = (HttpResponse) responseParts.poll();
   assertEquals(
       "Unexpected response status",
       range == null ? HttpResponseStatus.OK : HttpResponseStatus.PARTIAL_CONTENT,
       response.getStatus());
   checkCommonGetHeadHeaders(response.headers());
   assertEquals(
       "Content-Type does not match",
       expectedHeaders.get(RestUtils.Headers.AMBRY_CONTENT_TYPE),
       response.headers().get(HttpHeaders.Names.CONTENT_TYPE));
   assertEquals(
       RestUtils.Headers.BLOB_SIZE + " does not match",
       expectedHeaders.get(RestUtils.Headers.BLOB_SIZE),
       response.headers().get(RestUtils.Headers.BLOB_SIZE));
   assertEquals(
       "Accept-Ranges not set correctly",
       "bytes",
       response.headers().get(RestUtils.Headers.ACCEPT_RANGES));
   byte[] expectedContentArray = expectedContent.array();
   if (range != null) {
     long blobSize = Long.parseLong(expectedHeaders.get(RestUtils.Headers.BLOB_SIZE));
     assertEquals(
         "Content-Range header not set correctly",
         RestUtils.buildContentRangeAndLength(range, blobSize).getFirst(),
         response.headers().get(RestUtils.Headers.CONTENT_RANGE));
     ByteRange resolvedRange = range.toResolvedByteRange(blobSize);
     expectedContentArray =
         Arrays.copyOfRange(
             expectedContentArray,
             (int) resolvedRange.getStartOffset(),
             (int) resolvedRange.getEndOffset() + 1);
   } else {
     assertNull(
         "Content-Range header should not be set",
         response.headers().get(RestUtils.Headers.CONTENT_RANGE));
   }
   if (expectedContentArray.length < FRONTEND_CONFIG.frontendChunkedGetResponseThresholdInBytes) {
     assertEquals(
         "Content-length not as expected",
         expectedContentArray.length,
         HttpHeaders.getContentLength(response));
   }
   byte[] responseContentArray = getContent(responseParts, expectedContentArray.length).array();
   assertArrayEquals(
       "GET content does not match original content", expectedContentArray, responseContentArray);
   assertTrue("Channel should be active", HttpHeaders.isKeepAlive(response));
 }
コード例 #9
0
ファイル: RequestValidator.java プロジェクト: pageone/jbosh
  /*
   * The client MUST generate a large, random, positive integer for the
   * initial 'rid' (see Security Considerations) and then increment that
   * value by one for each subsequent request.
   *
   * @param node node to validate
   */
  private void assertSessionCreationRequestID(final Node node) {
    String ridStr = node.getBody().getAttribute(Attributes.RID);
    assertNotNull("Request ID attribute not present", ridStr);

    long rid = Long.parseLong(ridStr);
    assertTrue("RID was <= 0", rid > 0);

    // Not checking to see if it is "large" since it is already random
  }
コード例 #10
0
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    Product newProduct1 = new Product();
    Product newProduct2 = new Product();
    Product newProduct3 = new Product();

    // Test 1 = None of the values can be empty
    newProduct1.setProductId("CLO/1");
    newProduct1.setProductName("");
    newProduct1.setDescription("Nice Jacket");
    newProduct1.setQtyAvailable(Integer.parseInt("10"));
    newProduct1.setPrice(Double.parseDouble("15"));
    newProduct1.setBarCode(Long.parseLong("1345"));
    newProduct1.setReorderQty(Integer.parseInt("10"));
    newProduct1.setOrderQty(Integer.parseInt("100"));
    newProduct1.setCategory(Controller.getCategory("CLO"));

    // Test 2 = Price should be greater than zero
    newProduct2.setProductId("MUG/1");
    newProduct2.setProductName("NUS Mug");
    newProduct2.setDescription("Nice Mug");
    newProduct2.setQtyAvailable(Integer.parseInt("15"));
    newProduct2.setPrice(Double.parseDouble("0"));
    newProduct2.setBarCode(Long.parseLong("1345"));
    newProduct2.setReorderQty(Integer.parseInt("10"));
    newProduct2.setOrderQty(Integer.parseInt("100"));
    newProduct2.setCategory(Controller.getCategory("MUG"));

    // Test 3 = Non negative values
    newProduct3.setProductId("STA/1");
    newProduct3.setProductName("NUS Pen");
    newProduct3.setDescription("Nice Pen");
    newProduct3.setQtyAvailable(Integer.parseInt("-15"));
    newProduct3.setPrice(Double.parseDouble("10"));
    newProduct3.setBarCode(Long.parseLong("1345"));
    newProduct3.setReorderQty(Integer.parseInt("-10"));
    newProduct3.setOrderQty(Integer.parseInt("100"));
    newProduct3.setCategory(Controller.getCategory("STA"));

    products.add(newProduct1);
    products.add(newProduct2);
    products.add(newProduct3);
  }
コード例 #11
0
ファイル: RequestValidator.java プロジェクト: pageone/jbosh
 /*
  * The client MUST take care to choose an initial 'rid' that will never be
  * incremented above 9007199254740991 [21] within the session.
  *
  * @param node node to validate
  */
 private void assertSessionCreationRequestIDRange(final Node node) {
   String ridStr = node.getBody().getAttribute(Attributes.RID);
   long rid = Long.parseLong(ridStr);
   BigInteger biRID = BigInteger.valueOf(rid);
   BigInteger biMax = new BigInteger("9007199254740991");
   BigInteger biThreshold = BigInteger.valueOf(Math.round(Math.pow(2.0, 20.0)));
   assertTrue(
       "Initial RID leaves fewer than "
           + biThreshold.toString()
           + " total requests before max RID limit is hit",
       biRID.compareTo(biMax.subtract(biThreshold)) <= 0);
 }
コード例 #12
0
  @Test
  public void testGetVisitCount() {
    VisitCount visitCount = new VisitCount(helper);
    assertNotNull(visitCount);

    List<String> result = visitCount.getVisitCount("52", "180", "554");
    assertNotNull(result);
    assertTrue(result.size() == 3);

    long sum = 0;
    for (String count : result) {
      sum = sum + Long.parseLong(count);
    }
    String totalCount = visitCount.getVisitTotalCount();

    assertEquals(String.valueOf(sum), totalCount);
  }
コード例 #13
0
 /**
  * Gets the headers of the blob with blob ID {@code blobId} and verifies them against what is
  * expected.
  *
  * @param blobId the blob ID of the blob to HEAD.
  * @param range the {@link ByteRange} for the request.
  * @param expectedHeaders the expected headers in the response.
  * @throws ExecutionException
  * @throws InterruptedException
  */
 private void getHeadAndVerify(String blobId, ByteRange range, HttpHeaders expectedHeaders)
     throws ExecutionException, InterruptedException, RestServiceException {
   HttpHeaders headers = null;
   if (range != null) {
     headers =
         new DefaultHttpHeaders()
             .add(RestUtils.Headers.RANGE, RestTestUtils.getRangeHeaderString(range));
   }
   FullHttpRequest httpRequest = buildRequest(HttpMethod.HEAD, blobId, headers, null);
   Queue<HttpObject> responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
   HttpResponse response = (HttpResponse) responseParts.poll();
   assertEquals(
       "Unexpected response status",
       range == null ? HttpResponseStatus.OK : HttpResponseStatus.PARTIAL_CONTENT,
       response.getStatus());
   checkCommonGetHeadHeaders(response.headers());
   long contentLength = Long.parseLong(expectedHeaders.get(RestUtils.Headers.BLOB_SIZE));
   if (range != null) {
     Pair<String, Long> rangeAndLength =
         RestUtils.buildContentRangeAndLength(range, contentLength);
     assertEquals(
         "Content-Range header not set correctly",
         rangeAndLength.getFirst(),
         response.headers().get(RestUtils.Headers.CONTENT_RANGE));
     contentLength = rangeAndLength.getSecond();
   } else {
     assertNull(
         "Content-Range header should not be set",
         response.headers().get(RestUtils.Headers.CONTENT_RANGE));
   }
   assertEquals(
       "Accept-Ranges not set correctly",
       "bytes",
       response.headers().get(RestUtils.Headers.ACCEPT_RANGES));
   assertEquals(
       RestUtils.Headers.CONTENT_LENGTH + " does not match expected",
       contentLength,
       HttpHeaders.getContentLength(response));
   assertEquals(
       RestUtils.Headers.CONTENT_TYPE + " does not match " + RestUtils.Headers.AMBRY_CONTENT_TYPE,
       expectedHeaders.get(RestUtils.Headers.AMBRY_CONTENT_TYPE),
       HttpHeaders.getHeader(response, HttpHeaders.Names.CONTENT_TYPE));
   verifyBlobProperties(expectedHeaders, response);
   discardContent(responseParts, 1);
   assertTrue("Channel should be active", HttpHeaders.isKeepAlive(response));
 }
コード例 #14
0
  @Before
  public void setUp() throws DatastoreException, InvalidModelException, NotFoundException {
    // create a node
    Node toCreate = NodeTestUtils.createNew(name, userId);
    toCreate.setVersionComment("This is the first version of the first node ever!");
    toCreate.setVersionLabel("0.0.1");
    nodeId = nodeDAO.createNew(toCreate).substring(3); // trim "syn" from node ID

    // Initialize a new Evaluation
    EvaluationDBO evaluation = new EvaluationDBO();
    evaluation.setId(evalId);
    evaluation.seteTag("etag");
    evaluation.setName("name");
    evaluation.setOwnerId(userId);
    evaluation.setContentSource(KeyFactory.ROOT_ID);
    evaluation.setCreatedOn(System.currentTimeMillis());
    evaluation.setStatusEnum(EvaluationStatus.PLANNED);
    evalId = dboBasicDao.createNew(evaluation).getId();

    // Initialize a new Participant
    ParticipantDBO participant = new ParticipantDBO();
    participant.setUserId(userId);
    participant.setEvalId(evalId);
    participant.setCreatedOn(System.currentTimeMillis());
    participant.setId(idGenerator.generateNewId(TYPE.PARTICIPANT_ID));
    dboBasicDao.createNew(participant);

    // Initialize a new Submission
    SubmissionDBO submission = new SubmissionDBO();
    submission.setId(submissionId);
    submission.setName(name);
    submission.setEntityId(Long.parseLong(nodeId));
    submission.setVersionNumber(1L);
    submission.setUserId(userId);
    submission.setEvalId(evalId);
    submission.setCreatedOn(System.currentTimeMillis());
    dboBasicDao.createNew(submission);
  }
コード例 #15
0
  @Test
  public void testJMHPerfAnnotations() {
    String[] lines =
        new String[] {
          "                  Decoding compiled method 0x00007f25cd19c690:",
          "                  Code:",
          "                  [Entry Point]",
          "                  [Constants]",
          "                  # {method} {0x00007f25ccc5bc40} &apos;measureRight_avgt_jmhLoop&apos; &apos;(Lorg/openjdk/jmh/runner/InfraControl;Lorg/openjdk/jmh/results/RawResults;Lorg/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight$JMHSample_08_DeadCode_1_jmh;L",
          "                 <writer thread='139800227780352'/>",
          "                 <writer thread='139800228833024'/>",
          "                 org/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight$Blackhole_1_jmh;)V&apos; in &apos;org/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight&apos;",
          "                    # this:     rsi:rsi   = &apos;org/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight&apos;",
          "                    # parm0:    rdx:rdx   = &apos;org/openjdk/jmh/runner/InfraControl&apos;",
          "                    # parm1:    rcx:rcx   = &apos;org/openjdk/jmh/results/RawResults&apos;",
          "                    # parm2:    r8:r8     = &apos;org/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight$JMHSample_08_DeadCode_1_jmh&apos;",
          "                    # parm3:    r9:r9     = &apos;org/openjdk/jmh/samples/generated/JMHSample_08_DeadCode_measureRight$Blackhole_1_jmh&apos;",
          "                    #           [sp+0x30]  (sp of caller)",
          "                    0x00007f25cd19c7e0: mov    0x8(%rsi),%r10d",
          "                    0x00007f25cd19c7e4: shl    $0x3,%r10",
          "                    0x00007f25cd19c7e8: cmp    %r10,%rax",
          "                    0x00007f25cd19c7eb: jne    0x00007f25cd045b60  ;   {runtime_call}",
          "                    0x00007f25cd19c7f1: xchg   %ax,%ax",
          "                    0x00007f25cd19c7f4: nopl   0x0(%rax,%rax,1)",
          "                    0x00007f25cd19c7fc: xchg   %ax,%ax",
          "                  [Verified Entry Point]",
          "  1.34%             0x00007f25cd19c890: vmovsd 0xa0(%r13),%xmm0",
          "                    0x00007f25cd19c899: vmovsd 0x10(%r8),%xmm1    ;*getfield d1",
          "                                                                  ; - org.openjdk.jmh.infra.Blackhole::consume@2 (line 386)",
          "                                                                  ; - org.openjdk.jmh.samples.generated.JMHSample_08_DeadCode_measureRight::measureRight_avgt_jmhLoop@19 (line 160)",
          "                    0x00007f25cd19c89f: vmovsd 0xa8(%r13),%xmm2   ;*getfield d2",
          "                                                                  ; - org.openjdk.jmh.infra.Blackhole::consume@16 (line 386)",
          "                                                                  ; - org.openjdk.jmh.samples.generated.JMHSample_08_DeadCode_measureRight::measureRight_avgt_jmhLoop@19 (line 160)",
          "                    0x00007f25cd19c8a8: fldln2 ",
          "  1.61%             0x00007f25cd19c8aa: sub    $0x8,%rsp",
          "                    0x00007f25cd19c8ae: vmovsd %xmm1,(%rsp)",
          "                    0x00007f25cd19c8b3: fldl   (%rsp)",
          "  0.95%    0.02%    0x00007f25cd19c8b6: fyl2x  ",
          " 79.12%   95.68%    0x00007f25cd19c8b8: fstpl  (%rsp)",
          "  1.41%             0x00007f25cd19c8bb: vmovsd (%rsp),%xmm1",
          "  5.43%             0x00007f25cd19c8c0: add    $0x8,%rsp          ;*invokestatic log"
        };

    performAssemblyParsingOn(lines);

    IMetaMember member =
        map.get(
            "org.openjdk.jmh.samples.generated.JMHSample_08_DeadCode_measureRight measureRight_avgt_jmhLoop (Lorg.openjdk.jmh.runner.InfraControl;Lorg.openjdk.jmh.results.RawResults;Lorg.openjdk.jmh.samples.generated.JMHSample_08_DeadCode_measureRight$JMHSample_08_DeadCode_1_jmh;Lorg.openjdk.jmh.samples.generated.JMHSample_08_DeadCode_measureRight$Blackhole_1_jmh;)V");
    assertNotNull(member);

    AssemblyMethod assemblyMethod = member.getAssembly();

    assertNotNull(assemblyMethod);

    assertEquals(19, assemblyMethod.getMaxAnnotationWidth());

    // System.out.println(assemblyMethod.toString());

    List<AssemblyBlock> asmBlocks = assemblyMethod.getBlocks();

    assertEquals(2, asmBlocks.size());

    assertEquals(7, asmBlocks.get(0).getInstructions().size());
    assertEquals(11, asmBlocks.get(1).getInstructions().size());

    AssemblyInstruction instr9 = asmBlocks.get(1).getInstructions().get(8);

    assertEquals("79.12%   95.68%    ", instr9.getAnnotation());
    assertEquals(Long.parseLong("00007f25cd19c8b8", 16), instr9.getAddress());
    assertEquals("fstpl", instr9.getMnemonic());

    List<String> operands = new ArrayList<String>();
    operands.add("(%rsp)");

    assertEquals(operands, instr9.getOperands());
  }
コード例 #16
0
ファイル: Test.java プロジェクト: Kinyi/Merge_mr
  @org.junit.Test
  public void reduceTest() throws Exception {
    List<String> out_list = new ArrayList<String>();
    List<String> in_list = new ArrayList<String>();

    out_list.add(
        "13311361915;59;2015-10-30 13:44:21;2015-10-30 13:44:26;11985;150621;159;0;10.56.0.145");
    out_list.add(
        "13311361915;59;2015-10-30 13:17:27;2015-10-30 14:11:41;872979;2599118;3391;0;10.56.0.145");
    out_list.add("13311361915;59;2015-10-30 13:16:27;2015-10-30 13:18:41;2;3;4;0;10.56.0.145");
    out_list.add(
        "13311361915;59;2015-10-30 13:38:42;2015-10-30 13:39:16;2476;2016;5;0;10.56.0.145");
    out_list.add(
        "13311361915;59;2015-10-30 13:38:22;2015-10-30 13:44:19;10825;24953;35;0;10.56.0.145");

    in_list.add(
        "13311361915;59;2015-10-30 13:44:21;2015-10-30 13:44:26;11985;150621;159;0;10.56.0.145");
    in_list.add(
        "13311361915;59;2015-10-30 13:17:27;2015-10-30 14:11:41;872979;2599118;3391;0;10.56.0.145");
    in_list.add("13311361915;59;2015-10-30 13:16:27;2015-10-30 13:18:41;2;3;4;0;10.56.0.145");
    in_list.add("13311361915;59;2015-10-30 13:38:42;2015-10-30 13:39:16;2476;2016;5;0;10.56.0.145");
    in_list.add(
        "13311361915;59;2015-10-30 13:38:22;2015-10-30 13:44:19;10825;24953;35;0;10.56.0.145");

    // 对存储value值的两个list进行排序(按起始时间)
    Collections.sort(
        out_list,
        new Comparator<String>() {

          public int compare(String o1, String o2) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = null;
            Date date2 = null;
            try {
              date1 = sdf.parse(o1.substring(15, 34));
              date2 = sdf.parse(o2.substring(15, 34));
            } catch (ParseException e) {
              e.printStackTrace();
            }
            return date1.compareTo(date2);
          }
        });

    Collections.sort(
        in_list,
        new Comparator<String>() {

          public int compare(String o1, String o2) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date1 = null;
            Date date2 = null;
            try {
              date1 = sdf.parse(o1.substring(15, 34));
              date2 = sdf.parse(o2.substring(15, 34));
            } catch (ParseException e) {
              e.printStackTrace();
            }
            return date1.compareTo(date2);
          }
        });

    // 合并后的记录
    Set<String> merged_set = new HashSet<String>();
    // 合并过的记录
    Set<String> repeat_set = new HashSet<String>();

    // 日期格式化相关
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (String whole_out : out_list) {

      if (!repeat_set.contains(whole_out)) {

        String[] split_out = whole_out.split(";");

        long start_out = 0L;
        long end_out = 0L;
        long flux_out = 0L;
        try {
          start_out = sdf.parse(split_out[2]).getTime();
          end_out = sdf.parse(split_out[3]).getTime();
          flux_out = Long.parseLong(split_out[6]);
        } catch (ParseException e) {
          e.printStackTrace();
        }

        // 合并后的流量
        long flux_total = flux_out;
        // 合并后的起始时间
        long start_merged = start_out;
        // 合并后的结束时间
        long end_merged = end_out;

        for (String whole_in : in_list) {

          String[] split_in = whole_in.split(";");

          long start_in = 0L;
          long end_in = 0L;
          long flux_in = 0L;
          try {
            start_in = sdf.parse(split_in[2]).getTime();
            end_in = sdf.parse(split_in[3]).getTime();
            flux_in = Long.parseLong(split_in[6]);
          } catch (ParseException e) {
            e.printStackTrace();
          }

          // 不是自己本身的那条记录
          if (!whole_in.equals(whole_out)) {
            // 两条记录相互比较
            if (start_merged >= start_in && start_merged <= end_in
                || start_in >= start_merged && start_in <= end_merged) {
              flux_total = flux_total + flux_in;
              start_merged = Math.min(start_in, start_merged);
              end_merged = Math.max(end_in, end_merged);
              // 把合并过的记录保存到repeat_set
              repeat_set.add(whole_in);
            }
          }
        }
        merged_set.add(
            split_out[0]
                + "\t"
                + sdf.format(new Date(start_merged))
                + "\t"
                + sdf.format(new Date(end_merged))
                + "\t"
                + flux_total
                + "\t"
                + split_out[8]);
      } else {
        continue;
      }
    }

    for (String record : merged_set) {
      System.out.println(record);
    }
  }
コード例 #17
0
 @Test
 public void testSearchProperty() throws SQLException {
   rp = new ResidentialProperty();
   String[] ids = rp.searchProperty(130, 0, 0, 0, 0, "0", "0");
   assertEquals(130, Long.parseLong(ids[0]));
 }
コード例 #18
0
ファイル: DataIOTest.java プロジェクト: adridadou/mapdb
  @Test
  public void parity1() {
    assertEquals(Long.parseLong("1", 2), parity1Set(0));
    assertEquals(Long.parseLong("10", 2), parity1Set(2));
    assertEquals(Long.parseLong("111", 2), parity1Set(Long.parseLong("110", 2)));
    assertEquals(Long.parseLong("1110", 2), parity1Set(Long.parseLong("1110", 2)));
    assertEquals(Long.parseLong("1011", 2), parity1Set(Long.parseLong("1010", 2)));
    assertEquals(Long.parseLong("11111", 2), parity1Set(Long.parseLong("11110", 2)));

    assertEquals(0, parity1Get(Long.parseLong("1", 2)));
    try {
      parity1Get(Long.parseLong("0", 2));
      fail();
    } catch (DBException.PointerChecksumBroken e) {
      // TODO check mapdb specific error;
    }
    try {
      parity1Get(Long.parseLong("110", 2));
      fail();
    } catch (DBException.PointerChecksumBroken e) {
      // TODO check mapdb specific error;
    }
  }
コード例 #19
0
ファイル: KeyTest.java プロジェクト: 0003088/libelektra
 @Test
 public void test_keyWithLongValue_shouldPass() {
   Key key = Key.create(KEY_6_NAME, Key.KEY_VALUE, KEY_6_VALUE, Key.KEY_END);
   assertEquals(true, Long.parseLong(KEY_6_VALUE) == key.getLong().longValue());
 }
コード例 #20
0
ファイル: KeyTest.java プロジェクト: 0003088/libelektra
 @Test(expected = NumberFormatException.class)
 public void test_keyWithTooBigIntegerValue_shouldFail() {
   Key key = Key.create(KEY_6_NAME, Key.KEY_VALUE, KEY_6_VALUE, Key.KEY_END);
   // assert only to trigger key.getInteger() function which throws exception
   assertEquals(false, Long.parseLong(KEY_6_VALUE) == key.getInteger().intValue());
 }