コード例 #1
0
 /*
  * Test for Duration.hashcode(). hashcode() should return same value for
  * some equal durations.
  */
 @Test(dataProvider = "duration-for-hash")
 public void checkDurationHashCode(String lexRepresentation1, String lexRepresentation2) {
   Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
   Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
   int hash1 = duration1.hashCode();
   int hash2 = duration2.hashCode();
   assertTrue(hash1 == hash2, " generated hash1 : " + hash1 + " generated hash2 : " + hash2);
 }
コード例 #2
0
  /*
   * Test for add(Duration rhs).
   */
  @Test(dataProvider = "duration-for-add")
  public void checkDurationAdd(String initVal, String addVal, String result) {
    Duration durationInit = datatypeFactory.newDuration(initVal);
    Duration durationAdd = datatypeFactory.newDuration(addVal);
    Duration durationResult = datatypeFactory.newDuration(result);

    assertEquals(durationInit.add(durationAdd), durationResult);
  }
コード例 #3
0
  /*
   * Test for add(Duration rhs) 'rhs' is null , should throw NPE. "1 year" +
   * "-1 day" or "-1 year" + "1 day" should throw IllegalStateException
   */
  @Test(
      expectedExceptions = {NullPointerException.class, IllegalStateException.class},
      dataProvider = "duration-for-addneg")
  public void checkDurationAddNeg(String initVal, String addVal) {
    Duration durationInit = datatypeFactory.newDuration(initVal);
    Duration durationAdd = addVal == null ? null : datatypeFactory.newDuration(addVal);

    durationInit.add(durationAdd);
  }
コード例 #4
0
  /*
   * Test Duration#compare(Duration duration) with large durations.
   *
   * Bug # 4972785 UnsupportedOperationException is expected
   *
   */
  @Test(expectedExceptions = UnsupportedOperationException.class)
  public void checkDurationCompareLarge() {
    String duration1Lex = "P100000000000000000000D";
    String duration2Lex = "PT2400000000000000000000H";

    Duration duration1 = datatypeFactory.newDuration(duration1Lex);
    Duration duration2 = datatypeFactory.newDuration(duration2Lex);
    duration1.compare(duration2);
  }
コード例 #5
0
  /*
   * Test for Duration.negate().
   */
  @Test
  public void checkDurationNegate() {
    Duration durationPos = datatypeFactory.newDuration("P1Y0M0DT0H0M0S");
    Duration durationNeg = datatypeFactory.newDuration("-P1Y0M0DT0H0M0S");

    assertEquals(durationPos.negate(), durationNeg);
    assertEquals(durationNeg.negate(), durationPos);
    assertEquals(durationPos.negate().negate(), durationPos);
  }
コード例 #6
0
  /*
   * Test for - toString().
   */
  @Test(dataProvider = "number-string")
  public void checkDurationToString(
      boolean isPositive,
      int years,
      int months,
      int days,
      int hours,
      int minutes,
      int seconds,
      String lexical) {
    Duration duration =
        datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
    assertEquals(duration.toString(), lexical);

    assertEquals(datatypeFactory.newDuration(duration.toString()), duration);
  }
コード例 #7
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.tempuri.ITestService#generateLoadWithResponseData(java.lang.Integer
   * refID ,)javax.xml.datatype.Duration sleepTime ,)byte[] inputData
   * ,)java.lang.Integer outputDataSize )*
   */
  public org.datacontract.schemas._2004._07.services.StatisticInfo generateLoadWithResponseData(
      java.lang.Integer refID,
      javax.xml.datatype.Duration sleepTime,
      byte[] inputData,
      java.lang.Integer outputDataSize) {
    ServiceContext.Logger.traceEvent(Level.ALL, "Executing operation generateLoadWithResponseData");

    try {
      StatisticInfo info = new StatisticInfo();
      info.setRefID(refID);
      info.setStartTime(Utility.getXMLCurrentTime());
      if (inputData != null) {
        for (byte b : inputData) {
          System.out.print(b);
        }
      }
      Thread.sleep(sleepTime.getTimeInMillis(new Date()));

      String instanceid = System.getenv(EnvVarNames.CCP_TASKINSTANCEID);
      String taskid = System.getenv(EnvVarNames.CCP_TASKID);
      if (Utility.isNullOrEmpty(instanceid)) instanceid = "0";
      if (Utility.isNullOrEmpty(taskid)) taskid = "0";

      if (instanceid.equals("0"))
        info.setInstanceId(svcObjFact.createStatisticInfoInstanceId(taskid));
      else info.setInstanceId(svcObjFact.createStatisticInfoInstanceId(taskid + "." + instanceid));
      info.setEndTime(Utility.getXMLCurrentTime());

      return info;
    } catch (java.lang.Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
  }
コード例 #8
0
ファイル: datetime.java プロジェクト: chiragsanghavi/Tundra
  // adds the given xml duration to the given xml datetime returning the result
  public static java.util.Calendar add(
      java.util.Calendar calendar, javax.xml.datatype.Duration duration) {
    if (calendar == null || duration == null) return calendar;

    java.util.Calendar clone = (java.util.Calendar) calendar.clone();
    duration.addTo(clone);
    return clone;
  }
コード例 #9
0
  /*
   * Test for Duration.isShorterThan(Duration) and
   * Duration.isLongerThan(Duration).
   */
  @Test
  public void checkDurationShorterLonger() {
    Duration shorter = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
    Duration longer = datatypeFactory.newDuration("P2Y1M1DT1H1M1S");

    assertTrue(shorter.isShorterThan(longer));
    assertFalse(longer.isShorterThan(shorter));
    assertFalse(shorter.isShorterThan(shorter));

    assertTrue(longer.isLongerThan(shorter));
    assertFalse(shorter.isLongerThan(longer));
    assertFalse(shorter.isLongerThan(shorter));
  }
コード例 #10
0
 /*
  * (non-Javadoc)
  *
  * @see org.tempuri.ITestService#consumeCPU(javax.xml.datatype.Duration time
  * )*
  */
 public java.lang.String consumeCPU(javax.xml.datatype.Duration time) {
   ServiceContext.Logger.traceEvent(Level.ALL, "Executing operation consumeCPU");
   try {
     Pi PI = new Pi();
     PI.echo();
     return Pi.calculatePi(time.getTimeInMillis(new Date()));
   } catch (java.lang.Exception ex) {
     ex.printStackTrace();
     throw new RuntimeException(ex);
   }
 }
コード例 #11
0
  /*
   * (non-Javadoc)
   *
   * @see org.tempuri.ITestService#echoWithOnExit(java.lang.Integer refID
   * ,)javax.xml.datatype.Duration runTime ,)javax.xml.datatype.Duration
   * exitDelay ,)java.lang.String logPath )*
   */
  public org.datacontract.schemas._2004._07.services.ComputerInfo echoWithOnExit(
      java.lang.Integer refID,
      javax.xml.datatype.Duration runTime,
      javax.xml.datatype.Duration exitDelay,
      java.lang.String logPath) {
    ServiceContext.Logger.traceEvent(Level.ALL, "Executing operation echoWithOnExit");

    try {
      System.out.println("Start call " + refID.toString());
      ComputerInfo info = echo(refID);
      String taskInfo =
          String.format(
              "%s.%s.%s",
              System.getenv(EnvVarNames.CCP_JOBID),
              System.getenv(EnvVarNames.CCP_TASKID),
              System.getenv(EnvVarNames.CCP_TASKINSTANCEID));
      boolean isOnAzure =
          System.getenv(EnvVarNames.CCP_ONAZURE) != null
              && System.getenv(EnvVarNames.CCP_ONAZURE).equals("1");
      if (!isOnAzure && !Utility.isNullOrEmpty(logPath)) {
        writeLog(
            logPath + "\\CCP_AITest_Trace_" + String.valueOf(jobid),
            refID,
            "[Request] %s%%%s%%Svchost called.",
            Utility.getCurrentTime(),
            taskInfo);
      }
      System.out.format("[Request] %s%%%s%%Svchost called.%n", Utility.getCurrentTime(), taskInfo);
      EchoWithOnExitHandler onExit =
          new EchoWithOnExitHandler(exitDelay.getTimeInMillis(new Date()), logPath, refID, info);
      ServiceContext.exitingEvents.addMyEventListener(onExit);
      Thread.sleep(runTime.getTimeInMillis(new Date()));
      if (!info.isOnExitCalled()) {
        ServiceContext.exitingEvents.removedMyEventListener(onExit);
      }
      return info;
    } catch (java.lang.Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
  }
コード例 #12
0
  /*
   * Test Duration#getXMLSchemaType().
   *
   * Bug # 5049544 Duration.getXMLSchemaType shall return the correct result
   *
   */
  @Test
  public void checkDurationGetXMLSchemaType() {
    // DURATION
    Duration duration = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
    QName duration_xmlSchemaType = duration.getXMLSchemaType();
    assertEquals(
        duration_xmlSchemaType,
        DatatypeConstants.DURATION,
        "Expected DatatypeConstants.DURATION, returned " + duration_xmlSchemaType.toString());

    // DURATION_DAYTIME
    Duration duration_dayTime = datatypeFactory.newDuration("P1DT1H1M1S");
    QName duration_dayTime_xmlSchemaType = duration_dayTime.getXMLSchemaType();
    assertEquals(
        duration_dayTime_xmlSchemaType,
        DatatypeConstants.DURATION_DAYTIME,
        "Expected DatatypeConstants.DURATION_DAYTIME, returned "
            + duration_dayTime_xmlSchemaType.toString());

    // DURATION_YEARMONTH
    Duration duration_yearMonth = datatypeFactory.newDuration("P1Y1M");
    QName duration_yearMonth_xmlSchemaType = duration_yearMonth.getXMLSchemaType();
    assertEquals(
        duration_yearMonth_xmlSchemaType,
        DatatypeConstants.DURATION_YEARMONTH,
        "Expected DatatypeConstants.DURATION_YEARMONTH, returned "
            + duration_yearMonth_xmlSchemaType.toString());
  }
コード例 #13
0
ファイル: JavaMapping.java プロジェクト: phspaelti/basex
  /**
   * Returns an appropriate XQuery type for the specified Java object.
   *
   * @param o object
   * @return item type or {@code null} if no appropriate type was found
   */
  private static Type type(final Object o) {
    final Type t = type(o.getClass());
    if (t != null) return t;

    if (o instanceof Element) return NodeType.ELM;
    if (o instanceof Document) return NodeType.DOC;
    if (o instanceof DocumentFragment) return NodeType.DOC;
    if (o instanceof Attr) return NodeType.ATT;
    if (o instanceof Comment) return NodeType.COM;
    if (o instanceof ProcessingInstruction) return NodeType.PI;
    if (o instanceof Text) return NodeType.TXT;

    if (o instanceof Duration) {
      final Duration d = (Duration) o;
      return !d.isSet(DatatypeConstants.YEARS) && !d.isSet(DatatypeConstants.MONTHS)
          ? AtomType.DTD
          : !d.isSet(DatatypeConstants.HOURS)
                  && !d.isSet(DatatypeConstants.MINUTES)
                  && !d.isSet(DatatypeConstants.SECONDS)
              ? AtomType.YMD
              : AtomType.DUR;
    }

    if (o instanceof XMLGregorianCalendar) {
      final QName type = ((XMLGregorianCalendar) o).getXMLSchemaType();
      if (type == DatatypeConstants.DATE) return AtomType.DAT;
      if (type == DatatypeConstants.DATETIME) return AtomType.DTM;
      if (type == DatatypeConstants.TIME) return AtomType.TIM;
      if (type == DatatypeConstants.GYEARMONTH) return AtomType.YMO;
      if (type == DatatypeConstants.GMONTHDAY) return AtomType.MDA;
      if (type == DatatypeConstants.GYEAR) return AtomType.YEA;
      if (type == DatatypeConstants.GMONTH) return AtomType.MON;
      if (type == DatatypeConstants.GDAY) return AtomType.DAY;
    }
    return null;
  }
コード例 #14
0
  /*
   * (non-Javadoc)
   *
   * @see org.tempuri.ITestService#echoWithDelay(java.lang.Integer refID
   * ,)javax.xml.datatype.Duration delay )*
   */
  public org.datacontract.schemas._2004._07.services.ComputerInfo echoWithDelay(
      java.lang.Integer refID, javax.xml.datatype.Duration delay)
      throws ITestServiceEchoWithDelayAuthenticationFailureFaultFaultMessage,
          ITestServiceEchoWithDelayRetryOperationErrorFaultFaultMessage {
    ServiceContext.Logger.traceEvent(Level.ALL, "Executing operation echoWithDelay");

    try {
      System.out.println("Start call " + refID.toString());
      Thread.sleep((long) delay.getTimeInMillis(new Date()));
      return echo(refID);
    } catch (java.lang.Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
  }
コード例 #15
0
 protected void validateTimezone(DayTimeDurationValue offset) throws XPathException {
   Duration tz = offset.duration;
   Number secs = tz.getField(DatatypeConstants.SECONDS);
   if (secs != null && ((BigDecimal) secs).compareTo(BigDecimal.valueOf(0)) != 0)
     throw new XPathException(
         "duration " + offset + " has fractional minutes so cannot be used as a timezone offset");
   if (!(tz.equals(tzLowerBound)
       || tz.equals(tzUpperBound)
       || (tz.isLongerThan(tzLowerBound) && tz.isShorterThan(tzUpperBound))))
     throw new XPathException("duration " + offset + " outside valid timezone offset range");
 }
コード例 #16
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public boolean eIsSet(int featureID) {
   switch (featureID) {
     case PresentationPackage.SHOW_SHAPE_TYPE__SOUND:
       return sound != null;
     case PresentationPackage.SHOW_SHAPE_TYPE__DELAY:
       return DELAY_EDEFAULT == null ? delay != null : !DELAY_EDEFAULT.equals(delay);
     case PresentationPackage.SHOW_SHAPE_TYPE__DIRECTION:
       return isSetDirection();
     case PresentationPackage.SHOW_SHAPE_TYPE__EFFECT:
       return isSetEffect();
     case PresentationPackage.SHOW_SHAPE_TYPE__PATH_ID:
       return PATH_ID_EDEFAULT == null ? pathId != null : !PATH_ID_EDEFAULT.equals(pathId);
     case PresentationPackage.SHOW_SHAPE_TYPE__SHAPE_ID:
       return SHAPE_ID_EDEFAULT == null ? shapeId != null : !SHAPE_ID_EDEFAULT.equals(shapeId);
     case PresentationPackage.SHOW_SHAPE_TYPE__SPEED:
       return isSetSpeed();
     case PresentationPackage.SHOW_SHAPE_TYPE__START_SCALE:
       return isSetStartScale();
   }
   return super.eIsSet(featureID);
 }
コード例 #17
0
  /*
   * Test for Duration.getField(DatatypeConstants.Field).
   */
  @Test(dataProvider = "duration-fields")
  public void checkDurationGetField(
      String lexRepresentation,
      BigInteger years,
      BigInteger months,
      BigInteger days,
      BigInteger hours,
      BigInteger minutes,
      BigDecimal seconds) {
    Duration duration = datatypeFactory.newDuration(lexRepresentation);

    assertEquals(duration.getField(YEARS), years);
    assertEquals(duration.getField(MONTHS), months);
    assertEquals(duration.getField(DAYS), days);
    assertEquals(duration.getField(HOURS), hours);
    assertEquals(duration.getField(MINUTES), minutes);
    assertEquals(duration.getField(SECONDS), seconds);
  }
コード例 #18
0
 /*
  * Test for Duration.getSign().
  */
 @Test(dataProvider = "duration-sign")
 public void checkDurationSign(String lexRepresentation, int sign) {
   Duration duration = datatypeFactory.newDuration(lexRepresentation);
   assertEquals(duration.getSign(), sign);
 }
コード例 #19
0
  /*
   * Test for Duration.isSet().
   */
  @Test
  public void checkDurationIsSet() {
    Duration duration1 = datatypeFactory.newDuration(true, 1, 1, 1, 1, 1, 1);
    Duration duration2 = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);

    assertTrue(duration1.isSet(YEARS));
    assertTrue(duration1.isSet(MONTHS));
    assertTrue(duration1.isSet(DAYS));
    assertTrue(duration1.isSet(HOURS));
    assertTrue(duration1.isSet(MINUTES));
    assertTrue(duration1.isSet(SECONDS));

    assertTrue(duration2.isSet(YEARS));
    assertTrue(duration2.isSet(MONTHS));
    assertTrue(duration2.isSet(DAYS));
    assertTrue(duration2.isSet(HOURS));
    assertTrue(duration2.isSet(MINUTES));
    assertTrue(duration2.isSet(SECONDS));

    Duration duration66 = datatypeFactory.newDuration(true, null, null, zero, null, null, null);
    assertFalse(duration66.isSet(YEARS));
    assertFalse(duration66.isSet(MONTHS));
    assertFalse(duration66.isSet(HOURS));
    assertFalse(duration66.isSet(MINUTES));
    assertFalse(duration66.isSet(SECONDS));

    Duration duration3 = datatypeFactory.newDuration("P1D");
    assertFalse(duration3.isSet(YEARS));
    assertFalse(duration3.isSet(MONTHS));
    assertFalse(duration3.isSet(HOURS));
    assertFalse(duration3.isSet(MINUTES));
    assertFalse(duration3.isSet(SECONDS));
  }
コード例 #20
0
  /* (non-Javadoc)
   * @see org.tempuri.ITestService#trace(java.lang.Integer  refID ,)com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfstring  traceMsgs ,)javax.xml.datatype.Duration  sleepBeforeTrace ,)javax.xml.datatype.Duration  sleepAfterTrace ,)java.lang.Integer  testActionId )*
   */
  public org.datacontract.schemas._2004._07.services.ComputerInfo trace(
      java.lang.Integer refID,
      com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfstring traceMsgs,
      javax.xml.datatype.Duration sleepBeforeTrace,
      javax.xml.datatype.Duration sleepAfterTrace,
      java.lang.Integer testActionId)
      throws ITestServiceTraceRetryOperationErrorFaultFaultMessage,
          ITestServiceTraceOutOfMemoryExceptionFaultFaultMessage {
    LOG.info("Executing operation trace");
    ETWTraceEvent etw = new ETWTraceEvent(wsContext);
    etw.TraceEvent(
        JavaTraceLevelConverterEnum.Verbose, refID, "[HpcServiceHost]: Request is received.");
    Date callIn = new Date();

    etw.TraceEvent(JavaTraceLevelConverterEnum.Verbose, refID, "CallIn:" + callIn.toString());
    ComputerInfo info = buildComputerInfo(refID);

    try {
      info.setCallIn(Utility.convertXMLGregorianCalendar(callIn));
    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    if (TracingTestActionId.fromInteger(testActionId) == TracingTestActionId.TraceFaultException) {
      etw.TraceEvent(JavaTraceLevelConverterEnum.Error, refID, "ThrowFaultException");
      etw.TraceEvent(
          JavaTraceLevelConverterEnum.Verbose,
          refID,
          "[HpcServiceHost]: Response is sent back. IsFault = True");
      OutOfMemoryException err = new OutOfMemoryException();
      throw new ITestServiceTraceOutOfMemoryExceptionFaultFaultMessage("Testing fault.", err);

    } else if (TracingTestActionId.fromInteger(testActionId)
        == TracingTestActionId.RetryOperationError) {
      etw.TraceEvent(JavaTraceLevelConverterEnum.Error, refID, "ThrowRetryOperationError");
      etw.TraceEvent(
          JavaTraceLevelConverterEnum.Verbose,
          refID,
          "[HpcServiceHost]: Response is sent back. IsFault = True");
      RetryOperationError err = new RetryOperationError();
      throw new ITestServiceTraceRetryOperationErrorFaultFaultMessage(
          "Testting RetryOperationError.", err);
    } else if (TracingTestActionId.fromInteger(testActionId)
        == TracingTestActionId.TraceProcessExit) {
      etw.TraceEvent(JavaTraceLevelConverterEnum.Error, refID, "ProcessExit");
      etw.Flush();
      Utility.sleep(20 * 1000);
      Runtime.getRuntime().exit(refID);
      //            System.exit(refID);
    } else if (TracingTestActionId.fromInteger(testActionId) == TracingTestActionId.NoUserTrace) {
      try {
        info.setCallOut(Utility.convertXMLGregorianCalendar(new Date()));
        etw.TraceEvent(
            JavaTraceLevelConverterEnum.Verbose, refID, "CallOut:" + info.getCallOut().toString());
        return info;
      } catch (DatatypeConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    try {
      Thread.sleep(sleepBeforeTrace.getTimeInMillis(new Date()));
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    int count = 1;
    if (TracingTestActionId.fromInteger(testActionId) == TracingTestActionId.TraceLargeAmount) {
      count = 10000 / traceMsgs.getString().size();
    }
    for (int i = 0; i < count; i++) {
      for (String traceMsg : traceMsgs.getString()) {
        String[] splitters = traceMsg.split("\\|", 5);
        int iTracingType = Integer.parseInt(splitters[0]);
        int iEventType = Integer.parseInt(splitters[1]);
        int eventId = Integer.parseInt(splitters[2]);
        int sleepTime = Integer.parseInt(splitters[3]);
        String msg = splitters[4];
        TracingType tracingType = TracingType.fromInteger(iTracingType);
        JavaTraceLevelConverterEnum eventType =
            JavaTraceLevelConverterEnum.convertFromInteger(iEventType);
        if (tracingType == TracingType.TraceEvent) {
          etw.TraceEvent(eventType, eventId, msg);
          if (TracingTestActionId.fromInteger(testActionId)
              == TracingTestActionId.TraceRequestProcessing) {
            etw.Flush();
          }
        } else if (tracingType == TracingType.TraceInformation) {
          etw.TraceInformation(msg);
          if (TracingTestActionId.fromInteger(testActionId)
              == TracingTestActionId.TraceRequestProcessing) {
            etw.Flush();
          }
        } else if (tracingType == TracingType.TraceData) {
          if (TracingTestActionId.fromInteger(testActionId) == TracingTestActionId.TraceBigSize) {
            StringBuffer data = new StringBuffer();
            for (int j = 0; j < 63 * 512; j++) {
              data.append('0');
            }
            etw.TraceData(eventType, eventId, data);
            if (TracingTestActionId.fromInteger(testActionId)
                == TracingTestActionId.TraceRequestProcessing) {
              etw.Flush();
            }
            for (int j = 0; j < 2 * 512; j++) {
              data.append('1');
            }
            etw.TraceData(eventType, eventId, data);
            if (TracingTestActionId.fromInteger(testActionId)
                == TracingTestActionId.TraceRequestProcessing) {
              etw.Flush();
            }
          } else {
            TraceDataObj data = new TraceDataObj(msg);
            etw.TraceData(eventType, eventId, data);
            if (TracingTestActionId.fromInteger(testActionId)
                == TracingTestActionId.TraceRequestProcessing) {
              etw.Flush();
            }
          }
        } else if (tracingType == TracingType.TraceTransfer) {
          etw.TraceTransfer(eventId, msg, UUID.randomUUID());
        }
        Utility.sleep(sleepTime);
      }
    }
    Utility.sleep(sleepAfterTrace.getTimeInMillis(new Date()));
    try {
      info.setCallOut(Utility.convertXMLGregorianCalendar(new Date()));
    } catch (DatatypeConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    etw.TraceEvent(
        JavaTraceLevelConverterEnum.Verbose, refID, "CallOut:" + info.getCallOut().toString());
    etw.TraceEvent(
        JavaTraceLevelConverterEnum.Verbose,
        refID,
        "[HpcServiceHost]: Response is sent back. IsFault = False");
    return info;
  }
コード例 #21
0
  /*
   * (non-Javadoc)
   *
   * @see org.tempuri.ITestService#getCommonData(java.lang.Integer refID
   * ,)javax.xml.datatype.Duration sleepBeforeGet
   * ,)javax.xml.datatype.Duration sleepAfterGet ,)java.lang.String
   * dataClientId ,)java.lang.String expectedMd5Hash ,)java.lang.Integer
   * testActionId )*
   */
  public org.datacontract.schemas._2004._07.services.ComputerInfo getCommonData(
      java.lang.Integer refID,
      javax.xml.datatype.Duration sleepBeforeGet,
      javax.xml.datatype.Duration sleepAfterGet,
      java.lang.String dataClientId,
      java.lang.String expectedMd5Hash,
      java.lang.Integer testActionId)
      throws ITestServiceGetCommonDataCommonDataErrorFaultFaultMessage {
    ServiceContext.Logger.traceEvent(Level.ALL, "Executing operation getCommonData");
    try {
      switch (testActionId) {
        case Read_Raw_Bytes:
          long sleepTime = (long) sleepBeforeGet.getTimeInMillis(new Date());
          Thread.sleep(sleepTime);

          System.out.format(
              "%s: %d: Try to read raw common data for DataClient: %s\n",
              Utility.getCurrentTime(), refID, dataClientId);
          try {
            DataClient dataClient = ServiceContext.getDataClient(dataClientId);
            byte[] data = dataClient.readRawBytesAll();

            // Verify
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] md5Bytes = md.digest(data);
            String commonDataMd5Hash = "";
            for (byte b : md5Bytes) {
              commonDataMd5Hash += String.format("%02X", b);
            }
            if (!commonDataMd5Hash.equalsIgnoreCase(expectedMd5Hash)) {
              String output =
                  String.format(
                      "Corrupted common data in content. Expected md5: %s, actual md5: %s",
                      expectedMd5Hash, commonDataMd5Hash);
              System.out.println(output);
              throw new Exception(output);
            }

            System.out.format(
                "%s: %d: Common data for DataClient: %s validated",
                Utility.getCurrentTime(), refID, dataClientId);
            dataClient.close();
          } catch (Exception e) {
            boolean fileAccessable = false;
            try {
              String path = System.getenv("HPC_RUNTIMESHARE");
              if (!Utility.isNullOrEmpty(path)) {
                path += "\\Data";
                path += "\\" + String.valueOf(hashString(dataClientId));
              }
              System.out.println(path);
              fileAccessable = (new File(path)).exists();
            } catch (Exception e_alt) {
              // swallow
            }
            String errmsg =
                String.format(
                    "%s: %d: Unexpected exception thrown when reading data: %s\n",
                    Utility.getCurrentTime(), refID, e.toString());
            throw new Exception(
                String.format(
                    "ErrMsg: %s\nOutput: %s\nFileAccessable: %s",
                    errmsg, e.getMessage(), String.valueOf(fileAccessable)));
          }
          return echoWithDelay(refID, sleepAfterGet);
        case READ_AccessDenied:
        case READ_AccessDenied_ReadBytes:
        case No_Read_PerReq:
        case No_Read_Raw_PerReq:
        case Default:
        default:
          // unimplemented due to API difference
          return null;
      }
    } catch (java.lang.Exception ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
    // throw new
    // ITestServiceGetCommonDataCommonDataErrorFaultFaultMessage("ITestService_GetCommonData_CommonDataErrorFault_FaultMessage...");
  }
コード例 #22
0
  public Date add(Date date, Duration duration) {
    duration.addTo(date);

    return date;
  }
コード例 #23
0
 /*
  * getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
  * between startInstant and startInstant plus this Duration.
  */
 @Test
 public void checkDurationGetTimeInMillis() {
   Duration duration86 = datatypeFactory.newDuration("PT1M1S");
   Calendar calendar86 = Calendar.getInstance();
   assertEquals(duration86.getTimeInMillis(calendar86), 61000);
 }
コード例 #24
0
 /*
  * Test Duration.isSet(Field) throws NPE if the field parameter is null.
  */
 @Test(expectedExceptions = NullPointerException.class)
 public void checkDurationIsSetNeg() {
   Duration duration = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
   duration.isSet(null);
 }
コード例 #25
0
  public void TestXMLDuration() {
    DatatypeFactory factory = null;
    try {
      factory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
      errln("Error instantiating XML DatatypeFactory.");
      e.printStackTrace();
    }

    String cases[] = {
      "en", "PT10.00099S", "10 seconds",
      "en", "#10000", "10 seconds",
      "en", "-PT10.00099S", "10 seconds",
      "en", "#-10000", "10 seconds",

      // from BD req's
      "en", "PT2H46M40S", "2 hours, 46 minutes, and 40 seconds",
      "it", "PT2H46M40S", "due ore, 46 minuti e 40 secondi",

      // more cases
      "en", "PT10S", "10 seconds",
      "en", "PT88M70S", "88 minutes and 70 seconds",
      "en", "PT10.100S", "10 seconds and 100 milliseconds",
      "en", "-PT10S", "10 seconds",
      "en", "PT0H5M0S", "5 minutes and 0 seconds"
    };

    for (int n = 0; n < cases.length; n += 3) {
      String loc = cases[n + 0];
      String from = cases[n + 1];
      String to = cases[n + 2];

      ULocale locale = new ULocale(loc);
      Duration d;
      if (from.startsWith("#")) {
        d = factory.newDuration(Long.parseLong(from.substring(1)));
      } else {
        d = factory.newDuration(from);
      }

      DurationFormat df = DurationFormat.getInstance(locale);
      String output = df.format(d);

      if (output.equals(to)) {
        logln(
            "SUCCESS: locale: "
                + loc
                + ", from "
                + from
                + " ["
                + d.toString()
                + "] "
                + " to "
                + to
                + "= "
                + output);
      } else {
        logln(
            "FAIL: locale: "
                + loc
                + ", from "
                + from
                + " ["
                + d.toString()
                + "] "
                + ": expected "
                + to
                + " got "
                + output);
      }
    }
  }
コード例 #26
0
 /*
  * Test for -getField(DatatypeConstants.Field) DatatypeConstants.Field is
  * null - throws NPE.
  */
 @Test(expectedExceptions = NullPointerException.class)
 public void checkDurationGetFieldNeg() {
   Duration duration67 = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
   duration67.getField(null);
 }
コード例 #27
0
 /*
  * Test for - getField(SECONDS)
  */
 @Test
 public void checkDurationGetSecondsField() {
   Duration duration85 = datatypeFactory.newDuration("P1Y1M1DT1H1M100000000S");
   assertEquals((duration85.getField(SECONDS)).intValue(), 100000000);
 }
コード例 #28
0
ファイル: datetime.java プロジェクト: chiragsanghavi/Tundra
 // subtracts the given duration from the given datetime returning the result
 public static java.util.Calendar subtract(
     java.util.Calendar calendar, javax.xml.datatype.Duration duration) {
   if (duration != null) duration = duration.negate();
   return add(calendar, duration);
 }
コード例 #29
0
 public void testDuration() throws Exception {
   DatatypeFactory dtf = DatatypeFactory.newInstance();
   // arbitrary value
   Duration dur = dtf.newDurationDayTime(false, 15, 19, 58, 1);
   assertEquals(quote(dur.toString()), serializeAsString(dur));
 }
コード例 #30
0
 /*
  * getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
  * between startInstant and startInstant plus this Duration throws NPE if
  * startInstant parameter is null.
  */
 @Test(expectedExceptions = NullPointerException.class)
 public void checkDurationGetTimeInMillisNeg() {
   Duration duration87 = datatypeFactory.newDuration("PT1M1S");
   Calendar calendar87 = null;
   duration87.getTimeInMillis(calendar87);
 }