private static Date randomDate() {
   return Date.valueOf(
       LocalDate.of(
           RandomUtils.nextInt(1930, 1956),
           RandomUtils.nextInt(1, 13),
           RandomUtils.nextInt(1, 26)));
 }
Exemple #2
0
  @Test
  public void should_re_prepare_statements_when_cache_size_exceeded() throws Exception {
    // Given
    CompleteBean bean = builder().id(RandomUtils.nextLong(0, Long.MAX_VALUE)).name("name").buid();

    CompleteBean managed = pm.insert(bean);

    // When
    managed.setAge(10L);
    pm.update(managed);

    managed.setFriends(Arrays.asList("foo", "bar"));
    pm.update(managed);

    managed.setFollowers(Sets.newHashSet("George", "Paul"));
    pm.update(managed);

    managed.setAge(11L);
    pm.update(managed);

    // Then
    CompleteBean found = pm.find(CompleteBean.class, bean.getId());

    assertThat(found.getAge()).isEqualTo(11L);
    assertThat(found.getName()).isEqualTo("name");
    assertThat(found.getFriends()).containsExactly("foo", "bar");
    assertThat(found.getFollowers()).containsOnly("George", "Paul");
  }
  @Test
  public void should_check_for_common_operation_on_found_clustered_entity_by_iterator()
      throws Exception {
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 1);

    Iterator<ClusteredEntity> iter =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .iterator();

    iter.hasNext();
    ClusteredEntity clusteredEntity = iter.next();

    // Check for update
    clusteredEntity.setValue("dirty");
    manager.update(clusteredEntity);

    ClusteredEntity check = manager.find(ClusteredEntity.class, clusteredEntity.getId());
    assertThat(check.getValue()).isEqualTo("dirty");

    // Check for refresh
    check.setValue("dirty_again");
    manager.update(check);

    manager.refresh(clusteredEntity);
    assertThat(clusteredEntity.getValue()).isEqualTo("dirty_again");

    // Check for remove
    manager.delete(clusteredEntity);
    assertThat(manager.find(ClusteredEntity.class, clusteredEntity.getId())).isNull();
  }
  @Test
  public void should_iterate_with_custom_params() throws Exception {
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 5);
    insertClusteredValues(partitionKey, 1, "name2", 5);

    Iterator<ClusteredEntity> iter =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .fromClusterings(1, "name13")
            .toClusterings(1, "name21")
            .iterator(2);

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value13");

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value14");

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value15");

    assertThat(iter.hasNext()).isTrue();
    final ClusteredEntity next = iter.next();
    assertThat(next.getId().getName()).isEqualTo("name21");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iter.hasNext()).isFalse();
  }
  @Test
  public void should_iterate_with_partition_keys_and_partition_keys_IN_and_from_clusterings()
      throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);

    insertCompositeClusteredValues(partitionKey, "bucket1", 1, "abc", 1);
    insertCompositeClusteredValues(partitionKey, "bucket2", 1, "name", 1);
    insertCompositeClusteredValues(partitionKey, "bucket3", 1, "name", 1);

    // When
    final Iterator<CompositeClusteredEntity> iterator =
        manager
            .sliceQuery(CompositeClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .andPartitionComponentsIN("bucket1", "bucket3")
            .fromClusterings(1, "name1")
            .iterator();

    // Then
    assertThat(iterator.hasNext()).isTrue();
    CompositeClusteredEntity next = iterator.next();
    assertThat(next.getId().getBucket()).isEqualTo("bucket3");
    assertThat(next.getId().getName()).isEqualTo("name1");
    assertThat(next.getValue()).isEqualTo("value11");
  }
 @Test
 @Sql({"classpath:pdfBateriaPrueba.sql"})
 public void testIterateOverSecciones() throws Exception {
   Programa programa = programaDao.findOne(1);
   programa.setDuracion(RandomUtils.nextInt(1, 15));
   // programa.setIdDepAdmin("FEF");
   // programa.setDuracion(1);
   generar(programa);
 }
 /**
  * <div class="en"> Returns a number of random, lowercase, space-delimited words between
  * <b>min</b> and <b>max</b>. </div>
  *
  * <p><div class="ja"> Lorem Ipsum テキストより小文字で始まるランダム・ワードを <b>min</b> と <b>max</b> 間を戻します。(スペース句切れ)
  * </div>
  *
  * @param min <div class="en">the minimum number of words</div> <div class="ja">ワードの最小数</div>
  * @param max <div class="en">the maximum number of words</div> <div class="ja">ワードの最大数</div>
  * @return <div class="en">a string of space-delimited, randomly chosen words</div> <div
  *     class="ja">スペース句切れの数ワード</div>
  */
 public static String words(int min, int max) {
   if (min < 0) {
     min = 1;
   }
   if (max < min) {
     max = min + 1;
   }
   return words(RandomUtils.nextInt(0, min) + max - min + 1);
 }
  /**
   * <div class="en"> Returns a single, randomly chosen, lowercase word from Lorem text. </div>
   *
   * <p><div class="ja"> Lorem Ipsum テキストより小文字で始まるランダム・ワードを戻します </div>
   *
   * @return <div class="en">a string of a single, random word</div> <div
   *     class="ja">小文字で始まるランダム・ワード</div>
   */
  public static String word() {
    String paragraph = paragraph();
    int start = paragraph.indexOf(' ', RandomUtils.nextInt(0, paragraph.length() - 20));

    return paragraph
        .substring(start, paragraph.indexOf(' ', start + 1))
        .replaceAll("[.,;\\s]*$", "")
        .toLowerCase()
        .trim();
  }
  @Test
  public void should_dsl_select_slice_async() throws Exception {
    // Given
    final Map<String, Object> values = new HashMap<>();
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    values.put("id", id);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date date1 = dateFormat.parse("2015-10-01 00:00:00 GMT");
    final Date date9 = dateFormat.parse("2015-10-09 00:00:00 GMT");
    values.put("date1", "'2015-10-01 00:00:00+0000'");
    values.put("date2", "'2015-10-02 00:00:00+0000'");
    values.put("date3", "'2015-10-03 00:00:00+0000'");
    values.put("date4", "'2015-10-04 00:00:00+0000'");
    values.put("date5", "'2015-10-05 00:00:00+0000'");
    values.put("date6", "'2015-10-06 00:00:00+0000'");
    values.put("date7", "'2015-10-07 00:00:00+0000'");
    values.put("date8", "'2015-10-08 00:00:00+0000'");
    values.put("date9", "'2015-10-09 00:00:00+0000'");
    scriptExecutor.executeScriptTemplate("SimpleEntity/insert_many_rows.cql", values);

    final CountDownLatch latch = new CountDownLatch(1);
    final CassandraLogAsserter logAsserter = new CassandraLogAsserter();
    logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n");

    // When
    final CompletableFuture<List<SimpleEntity>> future =
        manager
            .dsl()
            .select()
            .consistencyList()
            .simpleSet()
            .simpleMap()
            .value()
            .simpleMap()
            .fromBaseTable()
            .where()
            .id()
            .Eq(id)
            .date()
            .Gte_And_Lt(date1, date9)
            .withResultSetAsyncListener(
                rs -> {
                  LOGGER.info(CALLED);
                  latch.countDown();
                  return rs;
                })
            .withTracing()
            .getListAsync();

    // Then
    latch.await();
    assertThat(future.get()).hasSize(8);
    logAsserter.assertContains("Called - [achilles-default-executor");
  }
Exemple #10
0
 public static String randomName() {
   List<String> results = new ArrayList<>();
   StringBuffer buffer = new StringBuffer();
   while (buffer.length() <= 15) {
     String result = WORDS.get(RandomUtils.nextInt(0, WORDS.size()));
     if (!results.contains(result)) {
       results.add(result);
       buffer.append(result);
     }
   }
   return org.apache.commons.lang3.StringUtils.join(results, " ");
 }
  /**
   * note that mmc4.scm has incorrect EvaluationLink structure, it should be (EvaluationLink
   * (PredicateNode ...) (ListLink (...) (...)))
   *
   * <p>i.e. PredicateNode should have no child ListLink
   *
   * @param parts
   * @param top
   * @return
   */
  public CypherPart evaluationToCypher(CypherParts parts, List<?> top) {
    final ArrayList<String> outDependencies = new ArrayList<>();
    final LinkedHashMap<String, Object> outParams = new LinkedHashMap<>();

    // ensure predicate is prepared
    final List<?> predicate = (List<?>) top.get(1);
    final String predicateName = (String) predicate.get(1);
    final String predicateType = typeNameFor(predicate);
    final String predicateVarName = varNameFor(predicateType, predicate);
    if (!parts.nodes.containsKey(predicateVarName)) {
      final CypherPart predicateCypher = customNodeToCypher(predicate);
      parts.nodes.put(predicateVarName, predicateCypher);
    }
    customNodeToMatch(predicate, outDependencies, outParams);

    // ensure all params are prepared
    final List<?> listLink = (List<?>) ((List<?>) top.get(1)).get(2);
    final List<List<?>> params = (List<List<?>>) listLink.subList(1, listLink.size());
    final List<String> paramNames = new ArrayList<>();
    for (List<?> param : params) {
      final String paramType = typeNameFor(param);
      final String paramVarName = varNameFor(paramType, param);
      if (!parts.nodes.containsKey(paramVarName)) {
        final CypherPart paramCypher = customNodeToCypher(param);
        parts.nodes.put(paramVarName, paramCypher);
      }
      customNodeToMatch(param, outDependencies, outParams);

      paramNames.add(paramVarName);
    }

    final String varName =
        "EvaluationLink_" + predicateName + "_" + RandomUtils.nextInt(1000, 10000);
    String create =
        String.format(
            "CREATE UNIQUE (%s:opencog_EvaluationLink) -[:opencog_predicate]-> (%s)",
            varName, predicateVarName);
    // http://schema.org/position
    for (int i = 0; i < paramNames.size(); i++) {
      create +=
          String.format(
              "\n  CREATE UNIQUE (%s) -[:opencog_parameter {position: %d}]-> (%s)",
              varName, i, paramNames.get(i));
    }

    final CypherPart part =
        new CypherPart(
            null, ImmutableMap.copyOf(outParams), create, ImmutableList.copyOf(outDependencies));
    parts.relationships.add(part);
    return part;
  }
  @Test
  public void should_dsl_update_value_async() throws Exception {
    // Given
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final Date date = buildDateKey();
    final AtomicBoolean success = new AtomicBoolean(false);
    scriptExecutor.executeScriptTemplate(
        "SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple"));

    final CountDownLatch latch = new CountDownLatch(1);
    final CassandraLogAsserter logAsserter = new CassandraLogAsserter();
    logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n");

    // When
    manager
        .dsl()
        .update()
        .fromBaseTable()
        .value()
        .Set("new value")
        .where()
        .id()
        .Eq(id)
        .date()
        .Eq(date)
        .if_Value()
        .Eq("0 AM")
        .withLwtResultListener(
            new LWTResultListener() {
              @Override
              public void onSuccess() {
                success.getAndSet(true);
              }

              @Override
              public void onError(LWTResult lwtResult) {}
            })
        .withResultSetAsyncListener(
            rs -> {
              LOGGER.info(CALLED);
              latch.countDown();
              return rs;
            })
        .executeAsync();

    // Then
    latch.await();
    logAsserter.assertContains("Called - [achilles-default-executor");
  }
 @Test
 @Sql({"classpath:pdfBateriaPrueba.sql"})
 public void testIterateOverSeccionesRechazado() throws Exception {
   Programa programa = programaDao.findOne(1);
   programa.setDuracion(RandomUtils.nextInt(1, 15));
   // programa.setDuracion(1);
   ProgramaEstatus estatusRechazado =
       ProgramaEstatus.builder()
           .idCatDepRevisora(1L)
           .idEstatus(EnumEstatusPrograma.RECHAZADO.getIdEstatus())
           .idPrograma(programa.getIdPrograma())
           .idUsuarioEjecutor(1L)
           .idEventoPrograma(CatEventoPrograma.RECHAZAR_PROGRAMA.getIdCatEventoPrograma())
           .build();
   programaEstatusJpaRepository.save(estatusRechazado);
   generar(programa);
 }
  @Test
  public void should_iterate_with_clustering_IN() throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 3);
    insertClusteredValues(partitionKey, 1, "name2", 2);
    insertClusteredValues(partitionKey, 1, "name3", 1);
    insertClusteredValues(partitionKey, 1, "name4", 1);

    // When
    final Iterator<ClusteredEntity> iterator =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .withClusterings(1)
            .andClusteringsIN("name11", "name12", "name13", "name41")
            .limit(100)
            .iterator(2);

    // Then
    assertThat(iterator.hasNext()).isTrue();
    ClusteredEntity next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name11");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name12");
    assertThat(next.getValue()).isEqualTo("value12");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name13");
    assertThat(next.getValue()).isEqualTo("value13");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name41");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isFalse();
  }
Exemple #15
0
  /**
   * 跳转至地理坐标选择组件
   *
   * @param mode 模式
   * @param formId 表单ID
   * @param fieldName 表单字段名称 用于带回选择的字段数据
   * @param lng 经度
   * @param lat 纬度
   * @param mm
   * @return
   */
  @RequestMapping(value = "/lookupGeographicCoordinates")
  public String lookupGeographicCoordinates(
      String mode, String formId, String fieldName, String lng, String lat, ModelMap mm) {
    mm.addAttribute("id", RandomUtils.nextInt(1, 100)); // 加入ID,避免同一组件冲突
    mm.addAttribute("formId", formId);
    mm.addAttribute("fieldName", fieldName);

    if (StringUtils.equals(mode, Constants.DISPLAY_MODE)) {
      mm.addAttribute("mode", mode);
    }
    if (StringUtils.isNotBlank(lng)) {
      mm.addAttribute("lng", lng);
    }
    if (StringUtils.isNotBlank(lat)) {
      mm.addAttribute("lat", lat);
    }

    return "/component/lookupGeographicCoordinates";
  }
  @Test
  public void should_iterate_over_clusterings_components() throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 3);
    insertClusteredValues(partitionKey, 2, "name2", 2);
    insertClusteredValues(partitionKey, 3, "name3", 1);
    insertClusteredValues(partitionKey, 4, "name4", 1);

    // When
    final Iterator<ClusteredEntity> iterator =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .fromClusterings(1)
            .fromInclusiveToExclusiveBounds()
            .limit(6)
            .iterator(2);

    // Then
    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value12");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value13");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value21");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value22");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value31");

    assertThat(iterator.hasNext()).isFalse();
  }
  @Test
  public void should_dsl_delete_async() throws Exception {
    // Given
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final Date date = buildDateKey();
    scriptExecutor.executeScriptTemplate(
        "SimpleEntity/insert_single_row.cql", ImmutableMap.of("id", id, "table", "simple"));

    final CountDownLatch latch = new CountDownLatch(1);
    final CassandraLogAsserter logAsserter = new CassandraLogAsserter();
    logAsserter.prepareLogLevel(ASYNC_LOGGER_STRING, "%msg - [%thread]%n");

    // When
    manager
        .dsl()
        .delete()
        .consistencyList()
        .simpleMap()
        .fromBaseTable()
        .where()
        .id()
        .Eq(id)
        .date()
        .Eq(date)
        .withResultSetAsyncListener(
            rs -> {
              LOGGER.info(CALLED);
              latch.countDown();
              return rs;
            })
        .withTracing()
        .executeAsync();

    // Then
    latch.await();
    logAsserter.assertContains("Called - ");
  }
 /**
  * <div class="en"> Returns a random sentence from the Lorem text. </div>
  *
  * <p><div class="ja"> Lorem Ipsum テキストよりランダム文を戻します。 </div>
  *
  * @return <div class="en">a string of a random sentence</div> <div class="ja">Lorem Ipsum
  *     テキストよりランダム文</div>
  */
 public static String sentence() {
   return sentence(paragraph(), RandomUtils.nextInt(0, 20) + 1);
 }
 private static int randomDuration() {
   return RandomUtils.nextInt(1900, 8801);
 }
 /**
  * <div class="en"> Returns a random paragraph of Lorem text. </div>
  *
  * <p><div class="ja"> Lorem Ipsum テキストより段落を一つ戻します。 </div>
  *
  * @return <div class="en">a string of one random paragraph of Lorem</div> <div class="ja">Lorem
  *     Ipsum テキストより段落</div>
  */
 public static String paragraph() {
   return _paragraphs[RandomUtils.nextInt(0, _paragraphs.length)];
 }