@After public void tearDown() throws Exception { super.tearDown(); serviceA.close(); serviceB.close(); threadPool.shutdown(); }
@After public void tearDown() throws Exception { super.tearDown(); reader.close(); writer.close(); ifdService.clear(); SearchContext.removeCurrent(); }
@Before public void setUp() throws Exception { super.setUp(); threadPool = new ThreadPool(); serviceA = build(ImmutableSettings.builder().put("name", "TS_A").build(), version0); nodeA = new DiscoveryNode( "TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version0); serviceB = build(ImmutableSettings.builder().put("name", "TS_B").build(), version1); nodeB = new DiscoveryNode( "TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version1); // wait till all nodes are properly connected and the event has been sent, so tests in this // class // will not get this callback called on the connections done in this setup final CountDownLatch latch = new CountDownLatch(4); TransportConnectionListener waitForConnection = new TransportConnectionListener() { @Override public void onNodeConnected(DiscoveryNode node) { latch.countDown(); } @Override public void onNodeDisconnected(DiscoveryNode node) { assert false : "disconnect should not be called " + node; } }; serviceA.addConnectionListener(waitForConnection); serviceB.addConnectionListener(waitForConnection); serviceA.connectToNode(nodeB); serviceA.connectToNode(nodeA); serviceB.connectToNode(nodeA); serviceB.connectToNode(nodeB); assertThat( "failed to wait for all nodes to connect", latch.await(5, TimeUnit.SECONDS), equalTo(true)); serviceA.removeConnectionListener(waitForConnection); serviceB.removeConnectionListener(waitForConnection); }
@Before public void setup() throws Exception { super.setUp(); // setup field mappers strMapper = new StringFieldMapper.Builder("str_value") .build(new Mapper.BuilderContext(null, new ContentPath(1))); lngMapper = new LongFieldMapper.Builder("lng_value") .build(new Mapper.BuilderContext(null, new ContentPath(1))); dblMapper = new DoubleFieldMapper.Builder("dbl_value") .build(new Mapper.BuilderContext(null, new ContentPath(1))); // create index and fielddata service ifdService = new IndexFieldDataService(new Index("test"), new DummyCircuitBreakerService()); MapperService mapperService = MapperTestUtils.newMapperService( ifdService.index(), ImmutableSettings.Builder.EMPTY_SETTINGS); ifdService.setIndexService(new StubIndexService(mapperService)); writer = new IndexWriter( new RAMDirectory(), new IndexWriterConfig(Lucene.VERSION, new StandardAnalyzer(Lucene.VERSION))); int numDocs = 10; for (int i = 0; i < numDocs; i++) { Document d = new Document(); d.add(new StringField(strMapper.names().indexName(), "str" + i, Field.Store.NO)); d.add(new LongField(lngMapper.names().indexName(), i, Field.Store.NO)); d.add(new DoubleField(dblMapper.names().indexName(), Double.valueOf(i), Field.Store.NO)); writer.addDocument(d); } reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(writer, true)); }
@Test public void testGetLeave() throws IOException { Path file = ElasticsearchTestCase.newTempDirPath(LifecycleScope.TEST); final int iters = scaledRandomIntBetween(10, 100); for (int i = 0; i < iters; i++) { { BaseDirectoryWrapper dir = newFSDirectory(file); FSDirectory directory = DirectoryUtils.getLeaf(new FilterDirectory(dir) {}, FSDirectory.class, null); assertThat(directory, notNullValue()); assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null))); dir.close(); } { BaseDirectoryWrapper dir = newFSDirectory(file); FSDirectory directory = DirectoryUtils.getLeaf(dir, FSDirectory.class, null); assertThat(directory, notNullValue()); assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null))); dir.close(); } { Set<String> stringSet = Collections.emptySet(); BaseDirectoryWrapper dir = newFSDirectory(file); FSDirectory directory = DirectoryUtils.getLeaf( new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean()), FSDirectory.class, null); assertThat(directory, notNullValue()); assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null))); dir.close(); } { Set<String> stringSet = Collections.emptySet(); BaseDirectoryWrapper dir = newFSDirectory(file); FSDirectory directory = DirectoryUtils.getLeaf( new FilterDirectory( new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean())) {}, FSDirectory.class, null); assertThat(directory, notNullValue()); assertThat(directory, sameInstance(DirectoryUtils.getLeafDirectory(dir, null))); dir.close(); } { Set<String> stringSet = Collections.emptySet(); BaseDirectoryWrapper dir = newFSDirectory(file); RAMDirectory directory = DirectoryUtils.getLeaf( new FilterDirectory( new FileSwitchDirectory(stringSet, dir, dir, random().nextBoolean())) {}, RAMDirectory.class, null); assertThat(directory, nullValue()); dir.close(); } } }