org.apache.ignite.internal.util.typedef.F.alwaysTrue()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(65)

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

F.alwaysTrue介绍

暂无

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public IgnitePredicate<ClusterNode> predicate() {
  return p != null ? p : F.<ClusterNode>alwaysTrue();
}

代码示例来源:origin: apache/ignite

/**
 * Negates given predicates.
 * <p>
 * Gets predicate (not peer-deployable) that evaluates to {@code true} if any of given predicates
 * evaluates to {@code false}. If all predicates evaluate to {@code true} the
 * result predicate will evaluate to {@code false}.
 *
 * @param p Predicate to negate.
 * @param <T> Type of the free variable, i.e. the element the predicate is called on.
 * @return Negated predicate (not peer-deployable).
 */
@SuppressWarnings("unchecked")
public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) {
  return F.isAlwaysFalse(p) ? F.<T>alwaysTrue() : F.isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
    @Override public boolean apply(T t) {
      return !F.isAll(t, p);
    }
  };
}

代码示例来源:origin: apache/ignite

/**
 * Negates given predicates.
 * <p>
 * Gets predicate that evaluates to {@code true} if any of given predicates
 * evaluates to {@code false}. If all predicates evaluate to {@code true} the
 * result predicate will evaluate to {@code false}.
 *
 * @param p Predicate to negate.
 * @param <T> Type of the free variable, i.e. the element the predicate is called on.
 * @return Negated predicate.
 */
@SafeVarargs
public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) {
  return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new IsNotAllPredicate<>(p);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testRedeploymentsAfterActivationOnAllNodes() throws Exception {
  checkRedeployment(2, 2, F.alwaysTrue(), 4, false);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testDeploymentsStaticConfigOnAllNodes() throws Exception {
  checkRedeployment(2, 2, F.alwaysTrue(), 4, true);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testRedeploymentsAfterActivationOnServers() throws Exception {
  checkRedeployment(2, 0, F.alwaysTrue(), 2, false);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testDeploymentsStaticConfigOnServers() throws Exception {
  checkRedeployment(2, 0, F.alwaysTrue(), 2, true);
}

代码示例来源:origin: apache/ignite

/**
   * @throws Exception If test failed
   */
  @Test
  public void testMultiThreaded() throws Exception {
    GridTestUtils.runMultiThreaded(new Callable<Object>() {
      @Override public Object call() throws Exception {
        for (int i = 0; i < 100000; i++)
          getSpi().record(new DiscoveryEvent(null, "Test event", 1, null));

        return null;
      }
    }, 10, "event-thread");

    Collection<Event> evts = getSpi().localEvents(F.<Event>alwaysTrue());

    info("Events count in memory: " + evts.size());

    assert evts.size() <= 10000 : "Incorrect number of events: " + evts.size();
  }
}

代码示例来源:origin: apache/ignite

@Override public void apply(IgniteInternalFuture<Collection<byte[]>> fut) {
    try {
      Collection<byte[]> grpKeys = fut.result();
      if (F.size(grpKeys, F.alwaysTrue()) != keyCnt)
        res.onDone(false, fut.error());
      IgniteInternalFuture<Boolean> dynStartCacheFut = after.apply(grpKeys);
      dynStartCacheFut.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
        @Override public void apply(IgniteInternalFuture<Boolean> fut) {
          try {
            res.onDone(fut.get(), fut.error());
          }
          catch (IgniteCheckedException e) {
            res.onDone(false, e);
          }
        }
      });
    }
    catch (Exception e) {
      res.onDone(false, e);
    }
  }
});

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public IgniteInternalFuture<?> deployAll(ClusterGroup prj, Collection<ServiceConfiguration> cfgs) {
  if (prj == null)
    // Deploy to servers by default if no projection specified.
    return deployAll(cfgs,  ctx.cluster().get().forServers().predicate());
  else if (prj.predicate() == F.<ClusterNode>alwaysTrue())
    return deployAll(cfgs,  null);
  else
    // Deploy to predicate nodes by default.
    return deployAll(cfgs,  prj.predicate());
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public IgniteInternalFuture<?> deployAll(ClusterGroup prj, Collection<ServiceConfiguration> cfgs) {
  if (prj == null)
    // Deploy to servers by default if no projection specified.
    return deployAll(cfgs, ctx.cluster().get().forServers().predicate());
  else if (prj.predicate() == F.<ClusterNode>alwaysTrue())
    return deployAll(cfgs, null);
  else
    // Deploy to predicate nodes by default.
    return deployAll(cfgs, prj.predicate());
}

代码示例来源:origin: apache/ignite

public void testRemoteNodeEventStorage() throws Exception {
  try {
    grid().events().remoteQuery(F.<Event>alwaysTrue(), 0);

代码示例来源:origin: apache/ignite

/**
 * @throws Exception In case of error.
 */
@Test
public void testLocalNodeEventStorage() throws Exception {
  try {
    grid().events().localQuery(F.<Event>alwaysTrue());
    assert false : "Exception must be thrown.";
  }
  catch (IgniteException e) {
    assertTrue(
      "Wrong exception message: " + e.getMessage(),
      e.getMessage().startsWith("Failed to query events because default no-op event storage SPI is used."));
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSpiFail() throws Exception {
  Ignite ignite = startGrid();
  try {
    try {
      ignite.events().localQuery(F.<Event>alwaysTrue());
      assert false : "Exception should be thrown";
    }
    catch (IgniteException e) {
      assert e.getMessage().startsWith(TEST_MSG) : "Wrong exception message." + e.getMessage();
    }
    try {
      ignite.compute().localDeployTask(GridTestTask.class, GridTestTask.class.getClassLoader());
      assert false : "Exception should be thrown";
    }
    catch (IgniteException e) {
      assertTrue(e.getCause() instanceof  IgniteCheckedException);
      Throwable err = e.getCause().getCause();
      assert err instanceof GridTestSpiException : "Wrong cause exception type. " + e;
      assert err.getMessage().startsWith(TEST_MSG) : "Wrong exception message." + e.getMessage();
    }
  }
  finally {
    stopGrid();
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testCustomClosure() throws Exception {
  for (int i = 0 ; i < NODES_CNT; i++) {
    log.info("Iteration: " + i);
    Ignite ignite = grid(i);
    Collection<String> res = ignite.compute(ignite.cluster().forPredicate(F.<ClusterNode>alwaysTrue())).
      broadcast(new IgniteCallable<String>() {
        @IgniteInstanceResource
        Ignite ignite;
        @Override public String call() throws Exception {
          return ignite.name();
        }
      });
    assertEquals(NODES_CNT, res.size());
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitForEventContinuationTimeout() throws Exception {
  Ignite ignite = grid();
  try {
    // We'll never wait for nonexistent type of event.
    int usrType = Integer.MAX_VALUE - 1;
    waitForLocalEvent(ignite.events(), F.<Event>alwaysTrue(), usrType).get(1000);
    fail("GridFutureTimeoutException must have been thrown.");
  }
  catch (IgniteFutureTimeoutException e) {
    info("Caught expected exception: " + e);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testFilter() throws Exception {
  MemoryEventStorageSpi spi = getSpi();
  try {
    spi.clearAll();
    spi.setFilter(F.<Event>alwaysFalse());
    // This event should not record.
    spi.record(createEvent());
    spi.setFilter(null);
    spi.record(createEvent());
    // Get all events.
    Collection<Event> evts = spi.localEvents(F.<Event>alwaysTrue());
    assert evts != null : "Events can't be null.";
    assert evts.size() == 1 : "Invalid events count: " + evts.size();
  }
  finally {
    if (spi != null)
      spi.clearAll();
  }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testUnloadEvents() throws Exception {
  final Ignite g1 = startGrid("g1");
  Collection<Integer> allKeys = new ArrayList<>(EVENTS_COUNT);
  IgniteCache<Integer, String> cache1 = g1.cache(DEFAULT_CACHE_NAME);
  IgniteCache<Integer, String> cache2 = g1.cache(DEFAULT_CACHE_NAME_EVTS_DISABLED);
  for (int i = 0; i < EVENTS_COUNT; i++) {
    cache1.put(i, "val");
    // Events should not be fired by this put.
    cache2.put(i, "val");
    allKeys.add(i);
  }
  Ignite g2 = startGrid("g2");
  awaitPartitionMapExchange(true, true, null);
  Map<ClusterNode, Collection<Object>> keysMap = g1.affinity(DEFAULT_CACHE_NAME).mapKeysToNodes(allKeys);
  Collection<Object> g2Keys = keysMap.get(g2.cluster().localNode());
  assertNotNull(g2Keys);
  assertFalse("There are no keys assigned to g2", g2Keys.isEmpty());
  Collection<Event> objEvts =
    g1.events().localQuery(F.<Event>alwaysTrue(), EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
  checkObjectUnloadEvents(objEvts, g1, g2Keys);
  Collection <Event> partEvts =
    g1.events().localQuery(F.<Event>alwaysTrue(), EVT_CACHE_REBALANCE_PART_UNLOADED);
  checkPartitionUnloadEvents(partEvts, g1, dht(g2.cache(DEFAULT_CACHE_NAME)).topology().localPartitions());
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception if failed.
 */
@Test
public void testPreloadEvents() throws Exception {
  Ignite g1 = startGrid("g1");
  IgniteCache<Integer, String> cache = g1.cache(DEFAULT_CACHE_NAME);
  cache.put(1, "val1");
  cache.put(2, "val2");
  cache.put(3, "val3");
  Ignite g2 = startGrid("g2");
  Collection<Event> evts = g2.events().localQuery(F.<Event>alwaysTrue(), EVT_CACHE_REBALANCE_OBJECT_LOADED);
  checkPreloadEvents(evts, g2, U.toIntList(new int[]{1, 2, 3}));
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception In case of error.
 */
@Test
public void testGridInternalEvents() throws Exception {
  IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
    @Override public boolean apply(Event evt) {
      checkGridInternalEvent(evt);
      return true;
    }
  };
  ignite1.events().localListen(lsnr, EVTS_TASK_EXECUTION);
  ignite1.events().localListen(lsnr, EVTS_JOB_EXECUTION);
  ignite2.events().localListen(lsnr, EVTS_TASK_EXECUTION);
  ignite2.events().localListen(lsnr, EVTS_JOB_EXECUTION);
  executeGridInternalTask(ignite1);
  Collection<Event> evts1 = ignite1.events().localQuery(F.<Event>alwaysTrue());
  Collection<Event> evts2 = ignite2.events().localQuery(F.<Event>alwaysTrue());
  assert evts1 != null;
  assert evts2 != null;
  for (Event evt : evts1)
    checkGridInternalEvent(evt);
  for (Event evt : evts2)
    checkGridInternalEvent(evt);
  assert ignite1.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
  assert ignite1.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
  assert ignite2.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
  assert ignite2.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
}

相关文章