コード例 #1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @SPITest
  public void missingIterableEntriesAreIgnoredByTheStore() throws Exception {
    final Store<K, V> kvStore =
        factory.newStore(
            factory.newConfiguration(
                factory.getKeyType(), factory.getValueType(), null, null, null));
    final K k1 = factory.createKey(1L);
    final V v1 = factory.createValue(1L);

    Set<K> set = new HashSet<K>();
    set.add(k1);

    kvStore.put(k1, v1);

    try {
      kvStore.bulkComputeIfAbsent(
          Arrays.asList((K[]) set.toArray()),
          new Function<
              Iterable<? extends K>, Iterable<? extends Map.Entry<? extends K, ? extends V>>>() {
            @Override
            public Iterable<? extends Map.Entry<? extends K, ? extends V>> apply(
                Iterable<? extends K> entries) {
              return new HashMap<K, V>().entrySet();
            }
          });
      assertThat(kvStore.get(k1).value(), is(v1));
    } catch (CacheAccessException e) {
      System.err.println("Warning, an exception is thrown due to the SPI test");
      e.printStackTrace();
    }
  }
コード例 #2
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 @SPITest
 public void testWrongKeyType() throws Exception {
   final Store<K, V> kvStore =
       factory.newStore(
           factory.newConfiguration(
               factory.getKeyType(), factory.getValueType(), null, null, null));
   Set<K> set = new HashSet<K>();
   if (factory.getKeyType() == String.class) {
     set.add((K) new Object());
   } else {
     set.add((K) "WrongKeyType");
   }
   try {
     kvStore.bulkComputeIfAbsent(
         Arrays.asList((K[]) set.toArray()),
         new Function<
             Iterable<? extends K>, Iterable<? extends Map.Entry<? extends K, ? extends V>>>() {
           @Override
           public Iterable<? extends Map.Entry<? extends K, ? extends V>> apply(
               Iterable<? extends K> entries) {
             throw new AssertionError(
                 "Expected ClassCastException because the key is of the wrong type");
           }
         });
     throw new AssertionError("Expected ClassCastException because the key is of the wrong type");
   } catch (ClassCastException e) {
     // expected
   } catch (CacheAccessException e) {
     System.err.println("Warning, an exception is thrown due to the SPI test");
     e.printStackTrace();
   }
 }