@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();
   }
 }
  @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();
    }
  }
Exemplo n.º 3
0
  @SPITest
  public void removesAllOfTheMappings()
      throws IllegalAccessException, InstantiationException, CacheAccessException {
    final Store<K, V> kvStore =
        factory.newStore(
            new StoreConfigurationImpl<K, V>(
                factory.getKeyType(),
                factory.getValueType(),
                null,
                Predicates.<Cache.Entry<K, V>>all(),
                null,
                ClassLoader.getSystemClassLoader(),
                Expirations.noExpiration()));

    K key = factory.getKeyType().newInstance();
    V value = factory.getValueType().newInstance();

    kvStore.put(key, value);

    try {
      kvStore.clear();
    } catch (CacheAccessException e) {
      System.err.println("Warning, an exception is thrown due to the SPI test");
      e.printStackTrace();
    }

    assertThat(kvStore.containsKey(key), is(false));
  }
Exemplo n.º 4
0
 @Test
 public void testPutNotSerializableKey() throws Exception {
   OnHeapStore<Serializable, Serializable> store = newStore();
   try {
     store.put(
         new ArrayList<Object>() {
           {
             add(new Object());
           }
         },
         "value");
     fail();
   } catch (CacheAccessException cae) {
     assertThat(cae.getCause(), instanceOf(SerializerException.class));
   }
 }