gpt4 book ai didi

com.epam.wilma.domain.sequence.WilmaSequence类的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 08:19:05 28 4
gpt4 key购买 nike

本文整理了Java中com.epam.wilma.domain.sequence.WilmaSequence类的一些代码示例,展示了WilmaSequence类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WilmaSequence类的具体详情如下:
包路径:com.epam.wilma.domain.sequence.WilmaSequence
类名称:WilmaSequence

WilmaSequence介绍

[英]This class represents a sequence.
[中]这个类代表一个序列。

代码示例

代码示例来源:origin: epam/Wilma

/**
 * Waits for the given sequence's responses to arrive.
 * Throws a {@link ResponseTimeoutException} if the waiting times out.
 * @param stubbedRequest the request that got stubbed
 * @param actualSequence the given request
 * @throws InterruptedException if the waiting is interrupted
 */
public void waitForResponses(final WilmaHttpRequest stubbedRequest, final WilmaSequence actualSequence) throws InterruptedException {
  String wilmaLoggerId = stubbedRequest.getWilmaMessageId();
  boolean allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId);
  int timeWaited = 0;
  getProperties();
  int waitInterval = properties.getWaitInterval();
  int timeout = properties.getTimeout();
  while (!allResponsesArrived) {
    Thread.sleep(waitInterval);
    timeWaited += waitInterval;
    if (timeWaited > timeout) {
      throw new ResponseTimeoutException(TIMEOUT_ERROR_MESSAGE);
    }
    allResponsesArrived = actualSequence.checkIfAllResponsesArrived(wilmaLoggerId);
  }
}

代码示例来源:origin: epam/Wilma

/**
 * Checks if all of the requests' responses arrived with the exception of the request with the given loggerId.
 * @param loggerId the given loggerId
 * @return true if all of the responses arrived (with the exception of the request's with the given loggerId), false otherwise
 */
public boolean checkIfAllResponsesArrived(final String loggerId) {
  Map<String, RequestResponsePair> pairs = getPairs();
  pairs.remove(loggerId);
  Iterator<RequestResponsePair> pairIterator = pairs.values().iterator();
  boolean result = true;
  while (pairIterator.hasNext() && result) {
    RequestResponsePair pair = pairIterator.next();
    result = pair.getResponse() != null;
  }
  return result;
}

代码示例来源:origin: epam/Wilma

@BeforeMethod
public void setUp() throws Exception {
  String sequenceKey = "key";
  Timestamp timestamp = new Timestamp(10);
  underTest = new WilmaSequence(sequenceKey, timestamp, messageStore);
}

代码示例来源:origin: epam/Wilma

private void appendSequence(final String sequenceKey, final WilmaHttpRequest request, final SequenceDescriptor sequenceDescriptor) {
  WilmaSequence sequence = sequenceDescriptor.getSequence(sequenceKey);
  if (sequence != null) {
    String loggerId = request.getWilmaMessageId();
    RequestResponsePair pair = new RequestResponsePair(requestCloner.cloneRequest(request));
    sequence.setTimeout(new Timestamp(dateProvider.getCurrentTimeInMillis() + sequenceDescriptor.getDefaultTimeout()));
    sequence.addPair(loggerId, pair);
  }
}

代码示例来源:origin: epam/Wilma

@Test
  public void testCreateNewSequence() {
    //GIVEN
    String testKey = "TestKey";
    String logggerId = "testId";
    given(request.getWilmaMessageId()).willReturn(logggerId);
    //WHEN
    WilmaSequence result = underTest.createNewSequence(testKey, request, 1000L);
    //THEN
    Assert.assertEquals(result.getSequenceKey(), testKey);
    Assert.assertFalse(result.isExpired(new Timestamp(1000L)));
    RequestResponsePair firstPair = result.getPairs().get(logggerId);
    Assert.assertEquals(firstPair.getRequest(), request);
  }
}

代码示例来源:origin: epam/Wilma

private void cleanSequences(final SequenceDescriptor sequenceDescriptor) {
    Iterator<WilmaSequence> iterator = sequenceDescriptor.getSequencesInCollection().iterator();
    while (iterator.hasNext()) {
      WilmaSequence actualSeq = iterator.next();
      if (actualSeq.isExpired(new Timestamp(dateProvider.getCurrentTimeInMillis()))) {
        iterator.remove();
      }
    }
  }
}

代码示例来源:origin: epam/Wilma

private void addResponseToSequence(final String sequenceId, final WilmaHttpResponse response) {
  String descriptorName = sequenceIdUtil.getDescriptorKey(sequenceId);
  SequenceDescriptor descriptor = descriptors.get(descriptorName);
  String handlerKey = sequenceIdUtil.getHandlerKey(sequenceId);
  if (descriptor != null) {
    WilmaSequence sequence = descriptor.getSequence(handlerKey);
    if (sequence != null) {
      sequence.addResponseToPair(responseCloner.cloneResponse(response));
    }
  }
}

代码示例来源:origin: epam/Wilma

/**
 * Put a new sequence object into the sequences collection.
 * @param sequence is the new sequence what we want to store
 */
public void putIntoSequences(final WilmaSequence sequence) {
  sequences.put(sequence.getSequenceKey(), sequence);
}

代码示例来源:origin: epam/Wilma

@Test
public void testCheckRequestShouldAppendRequestToAnExistingSequence() {
  //GIVEN
  String sequenceKeyFirst = "testKey1";
  Map<String, WilmaSequence> sequences = new ConcurrentHashMap<>();
  sequences.put(sequenceKeyFirst, sequenceFirst);
  given(sequenceEvaluator.evaluate(request, sequenceDescriptor)).willReturn(true);
  given(sequenceDescriptor.getSequences()).willReturn(sequences);
  given(handler.getExistingSequence(request, sequences, null)).willReturn(sequenceKeyFirst);
  given(sequenceDescriptor.getSequence(sequenceKeyFirst)).willReturn(sequenceFirst);
  given(request.getWilmaMessageId()).willReturn("TestLoggerId");
  given(sequenceIdUtil.createSequenceId(sequenceKeyFirst, sequenceDescriptor)).willReturn("newID");
  given(request.getSequenceId()).willReturn(null);
  given(headerUtil.createSequenceHeader(null, "newID")).willReturn("newID");
  //WHEN
  underTest.checkRequest(request, sequenceDescriptor);
  //THEN
  verify(sequenceFirst).setTimeout(Mockito.any(Timestamp.class));
  verify(sequenceFirst).addPair(Mockito.eq("TestLoggerId"), Mockito.any(RequestResponsePair.class));
  verify(request).addSequenceId("newID");
}

代码示例来源:origin: epam/Wilma

@Test
public void testCleanTheExpiredSequences() {
  //GIVEN
  descriptors.put("TestKey1", descriptor);
  List<WilmaSequence> sequences = new ArrayList<>();
  sequences.add(firstSequence);
  sequences.add(secondSequence);
  given(descriptor.getSequencesInCollection()).willReturn(sequences);
  given(firstSequence.isExpired(new Timestamp(1000L))).willReturn(false);
  given(secondSequence.isExpired(new Timestamp(1000L))).willReturn(true);
  //WHEN
  underTest.cleanTheExpiredSequences(descriptors);
  //THEN
  Assert.assertEquals(sequences.size(), 1);
}

代码示例来源:origin: epam/Wilma

@Test
public void testTryToSaveResponseIntoSequence() {
  //GIVEN
  response = new WilmaHttpResponse(isVolatile);
  String sequenceKey = "TestTeam-fistDescriptor-TestHandler|Sequence1";
  Map<String, String> requestHeaders = new HashMap<>();
  requestHeaders.put(WilmaHttpEntity.WILMA_SEQUENCE_ID, sequenceKey);
  Map<String, SequenceDescriptor> descriptors = new ConcurrentHashMap<>();
  descriptors.put("TestTeam-fistDescriptor-TestHandler", sequenceDescriptor);
  Whitebox.setInternalState(response, "requestHeaders", requestHeaders);
  Whitebox.setInternalState(underTest, "descriptors", descriptors);
  given(headerUtil.resolveSequenceHeader(sequenceKey)).willReturn(new String[]{sequenceKey});
  given(sequenceKeyResolver.getDescriptorKey(sequenceKey)).willReturn("TestTeam-fistDescriptor-TestHandler");
  given(sequenceKeyResolver.getHandlerKey(sequenceKey)).willReturn("Sequence1");
  given(sequenceDescriptor.getSequence("Sequence1")).willReturn(sequence);
  //WHEN
  underTest.tryToSaveResponseIntoSequence(response);
  //THEN
  verify(sequence).addResponseToPair(clonedResponse);
}

代码示例来源:origin: epam/Wilma

@Test
public void testCheckRequestShouldCreateANewSequence() {
  //GIVEN
  String sequenceKeyFirst = "testKey1";
  String sequenceKeySecond = "testKey2";
  Map<String, WilmaSequence> sequences = new ConcurrentHashMap<>();
  sequences.put(sequenceKeyFirst, sequenceFirst);
  given(sequenceEvaluator.evaluate(request, sequenceDescriptor)).willReturn(true);
  given(handler.getExistingSequence(request, sequences, null)).willReturn(null);
  given(handler.generateNewSequenceKey(request, null)).willReturn(sequenceKeySecond);
  given(sequenceDescriptor.getDefaultTimeout()).willReturn(1000L);
  given(sequenceFactory.createNewSequence(sequenceKeySecond, request, 1000L)).willReturn(sequenceSecond);
  given(sequenceSecond.getSequenceKey()).willReturn(sequenceKeySecond);
  given(sequenceIdUtil.createSequenceId(sequenceKeySecond, sequenceDescriptor)).willReturn("newID");
  given(request.getSequenceId()).willReturn(null);
  given(headerUtil.createSequenceHeader(null, "newID")).willReturn("newID");
  //WHEN
  underTest.checkRequest(request, sequenceDescriptor);
  //THEN
  verify(sequenceDescriptor).putIntoSequences(sequenceSecond);
  verify(request).addSequenceId("newID");
}

代码示例来源:origin: epam/Wilma

@Test
  public void testWaitForResponses() throws InterruptedException {
    //GIVEN
    given(actualSequence.checkIfAllResponsesArrived(LOGGER_ID)).willReturn(false, false, false, true);
    //WHEN
    underTest.waitForResponses(stubbedRequest, actualSequence);
    //THEN
    verify(actualSequence, times(4)).checkIfAllResponsesArrived(LOGGER_ID);
  }
}

代码示例来源:origin: epam/Wilma

private String getReferredSource(final String expression) {
  String[] parts = expression.substring(1).split("\\.");
  String link = parts[0];
  String linkedContent;
  if (SELF_REQUEST_REFFERENCE.equals(link)) {
    linkedContent = getSource();
  } else {
    Map<String, String> map = sequenceJsonTransformer.transform(params, sequence.getPairs());
    linkedContent = map.get(link);
  }
  return linkedContent;
}

代码示例来源:origin: epam/Wilma

/**
   * This method creates new WilmaSequence object from the given parameters.
   * @param sequenceKey is the key of the new WilmaSequence
   * @param request is the first request of the new WilmaSequence
   * @param timeout is time in milliseconds when the sequence will be expired
   * @return with the new WilmaSequence object.
   */
  public WilmaSequence createNewSequence(final String sequenceKey, final WilmaHttpRequest request, final long timeout) {
    WilmaSequencePairs messageStore = new WilmaSequencePairs();
    RequestResponsePair firstPair = new RequestResponsePair(request);
    String loggerId = request.getWilmaMessageId();
    messageStore.addStore(loggerId, firstPair);
    WilmaSequence sequence = new WilmaSequence(sequenceKey, new Timestamp(dateProvider.getCurrentTimeInMillis() + timeout), messageStore);
    return sequence;
  }
}

代码示例来源:origin: epam/Wilma

@Test(expectedExceptions = ResponseTimeoutException.class)
public void testWhenResponsesCannotArriveInTimeThenExceptionIsThrown() throws InterruptedException {
  //GIVEN
  given(actualSequence.checkIfAllResponsesArrived(LOGGER_ID)).willReturn(false);
  //WHEN
  underTest.waitForResponses(stubbedRequest, actualSequence);
  //THEN exception is thrown
}

代码示例来源:origin: epam/Wilma

@Override
public byte[] formatResponse(final WilmaHttpRequest wilmaRequest, final HttpServletResponse resp,
               final byte[] templateResource, final ParameterList params) {
  Map<String, RequestResponsePair> message = wilmaRequest.getSequence().getPairs();
  Map<String, String> nameToXml = sequenceXmlTransformer.transform(params, message);
  String xslResourcePath = checkAndGetXslResourcePath(params);
  byte[] xslResource = readXslResourceFromFileSystem(xslResourcePath);
  byte[] requestXmlResource = wilmaRequest.getBody().getBytes(StandardCharsets.UTF_8);
  return xslResponseGenerator.generateResponse(requestXmlResource, xslResource, templateResource, nameToXml);
}

代码示例来源:origin: epam/Wilma

@Test
public void testCheckShouldNotLookForResponsePairOfTheGivenLoggerId() {
  //GIVEN
  Map<String, RequestResponsePair> messages = new HashMap<>();
  RequestResponsePair pair = new RequestResponsePair(new WilmaHttpRequest());
  messages.put(STUBBED_REQUEST_LOGGER_ID, pair);
  given(messageStore.getMessages()).willReturn(messages);
  //WHEN
  boolean result = underTest.checkIfAllResponsesArrived(STUBBED_REQUEST_LOGGER_ID);
  //THEN
  assertTrue(result);
}

代码示例来源:origin: epam/Wilma

@Test
public void testCheckShouldReturnFalseWhenAResponseIsNull() {
  //GIVEN
  Map<String, RequestResponsePair> messages = new TreeMap<>();
  RequestResponsePair pair = new RequestResponsePair(new WilmaHttpRequest());
  pair.setResponse(new WilmaHttpResponse(isVolatile));
  RequestResponsePair pair2 = new RequestResponsePair(new WilmaHttpRequest());
  messages.put("id2", pair);
  messages.put("id3", pair2);
  given(messageStore.getMessages()).willReturn(messages);
  //WHEN
  boolean result = underTest.checkIfAllResponsesArrived(STUBBED_REQUEST_LOGGER_ID);
  //THEN
  assertFalse(result);
}

代码示例来源:origin: epam/Wilma

@Test
  public void testCheckShouldReturnTrueWhenNoneOfTheResponsesAreNull() {
    //GIVEN
    Map<String, RequestResponsePair> messages = new TreeMap<>();
    RequestResponsePair pair = new RequestResponsePair(new WilmaHttpRequest());
    pair.setResponse(new WilmaHttpResponse(isVolatile));
    RequestResponsePair pair2 = new RequestResponsePair(new WilmaHttpRequest());
    pair2.setResponse(new WilmaHttpResponse(isVolatile));
    messages.put("id2", pair);
    messages.put("id3", pair2);
    given(messageStore.getMessages()).willReturn(messages);
    //WHEN
    boolean result = underTest.checkIfAllResponsesArrived(STUBBED_REQUEST_LOGGER_ID);
    //THEN
    assertTrue(result);
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com