public void testRegisterTaskStatus() { NamedWriteableRegistry registry = new NamedWriteableRegistry(); Settings settings = Settings.EMPTY; NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, registry); // Builtin reader comes back assertNotNull(registry.getReader(Task.Status.class, ReplicationTask.Status.NAME)); module.registerTaskStatus(DummyTaskStatus.NAME, DummyTaskStatus::new); assertEquals( "test", expectThrows( UnsupportedOperationException.class, () -> registry.getReader(Task.Status.class, DummyTaskStatus.NAME).read(null)) .getMessage()); }
static SmoothingModel copyModel(SmoothingModel original) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { original.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput( output.bytes().streamInput(), namedWriteableRegistry)) { return namedWriteableRegistry .getReader(SmoothingModel.class, original.getWriteableName()) .read(in); } } }
@Inject public IndicesQueriesRegistry( Settings settings, Set<QueryParser> injectedQueryParsers, NamedWriteableRegistry namedWriteableRegistry) { super(settings); Map<String, QueryParser<?>> queryParsers = new HashMap<>(); for (@SuppressWarnings("unchecked") QueryParser<? extends QueryBuilder> queryParser : injectedQueryParsers) { for (String name : queryParser.names()) { queryParsers.put(name, queryParser); } @SuppressWarnings("unchecked") NamedWriteable<? extends QueryBuilder> qb = queryParser.getBuilderPrototype(); namedWriteableRegistry.registerPrototype(QueryBuilder.class, qb); } // EmptyQueryBuilder is not registered as query parser but used internally. // We need to register it with the NamedWriteableRegistry in order to serialize it namedWriteableRegistry.registerPrototype(QueryBuilder.class, EmptyQueryBuilder.PROTOTYPE); this.queryParsers = unmodifiableMap(queryParsers); }
/** Setup for the whole base test class. */ @BeforeClass public static void init() { NamedWriteableRegistry nwRegistry = new NamedWriteableRegistry(); nwRegistry.registerPrototype(SuggestionBuilder.class, TermSuggestionBuilder.PROTOTYPE); nwRegistry.registerPrototype(SuggestionBuilder.class, PhraseSuggestionBuilder.PROTOTYPE); nwRegistry.registerPrototype(SuggestionBuilder.class, CompletionSuggestionBuilder.PROTOTYPE); nwRegistry.registerPrototype(SmoothingModel.class, Laplace.PROTOTYPE); nwRegistry.registerPrototype(SmoothingModel.class, LinearInterpolation.PROTOTYPE); nwRegistry.registerPrototype(SmoothingModel.class, StupidBackoff.PROTOTYPE); namedWriteableRegistry = nwRegistry; }