@Test public void testReuse() throws Exception { Directory dir = newDirectory(); // test that IWC cannot be reused across two IWs IndexWriterConfig conf = newIndexWriterConfig(null); new RandomIndexWriter(random(), dir, conf).close(); // this should fail try { assertNotNull(new RandomIndexWriter(random(), dir, conf)); fail("should have hit AlreadySetException"); } catch (AlreadySetException e) { // expected } dir.close(); }
public void testForceCustomQueryCache() throws IOException { Settings indexSettings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings), new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap())); module.forceQueryCacheProvider((a, b) -> new CustomQueryCache()); expectThrows(AlreadySetException.class, () -> module.forceQueryCacheProvider((a, b) -> new CustomQueryCache())); IndexService indexService = newIndexService(module); assertTrue(indexService.cache().query() instanceof CustomQueryCache); indexService.close("simon says", false); }
@Test(expected=AlreadySetException.class) public void testSetOnce() throws Exception { SetOnce<Integer> set = new SetOnce<>(); set.set(new Integer(5)); assertEquals(5, set.get().intValue()); set.set(new Integer(7)); }
@Test(expected=AlreadySetException.class) public void testSetOnce() throws Exception { SetOnce<Integer> set = new SetOnce<Integer>(); set.set(new Integer(5)); assertEquals(5, set.get().intValue()); set.set(new Integer(7)); }
@Test(expected=AlreadySetException.class) public void testSettingCtor() throws Exception { SetOnce<Integer> set = new SetOnce<>(new Integer(5)); assertEquals(5, set.get().intValue()); set.set(new Integer(7)); }
@Test(expected=AlreadySetException.class) public void testSettingCtor() throws Exception { SetOnce<Integer> set = new SetOnce<Integer>(new Integer(5)); assertEquals(5, set.get().intValue()); set.set(new Integer(7)); }