X
stringlengths 236
264k
| y
stringlengths 5
74
|
|---|---|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void [MASK] Class() {
Mono<String> result = Mono.just("foo");
given(mockRequest. [MASK] (String.class)).willReturn(result);
assertThat(wrapper. [MASK] (String.class)).isSameAs(result);
}
@Test
void [MASK] ParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest. [MASK] (reference)).willReturn(result);
assertThat(wrapper. [MASK] (reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
bodyToMono
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf. [MASK] input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
CodedInputStream
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse. [MASK] )).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse. [MASK] )).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse. [MASK] );
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
ACKNOWLEDGED_NO_ERRORS
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest. [MASK] ;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.get [MASK] (),
contains(
[MASK] .add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
[MASK] .remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.get [MASK] (),
contains( [MASK] .add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
AliasActions
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client. [MASK] .AdminClient;
import org.elasticsearch.client. [MASK] .Client;
import org.elasticsearch.client. [MASK] .ClusterAdminClient;
import org.elasticsearch.client. [MASK] .IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
internal
|
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.vm.ci.code;
/**
* Represents a compiled instance of a method. It may have been invalidated or removed in the
* meantime.
*/
public class InstalledCode {
/**
* Address of the entity (e.g., HotSpot {@code nmethod} or {@code RuntimeStub}) representing
* this installed code.
*/
protected long address;
/**
* Address of the [MASK] of this installed code.
*/
protected long [MASK] ;
/**
* Counts how often the address field was reassigned.
*/
protected long version;
protected final String name;
public InstalledCode(String name) {
this.name = name;
}
/**
* @return the address of entity (e.g., HotSpot {@code nmethod} or {@code RuntimeStub})
* representing this installed code
*/
public long getAddress() {
return address;
}
/**
* @return the address of the normal entry point of the installed code.
*/
public long getEntryPoint() {
return [MASK] ;
}
/**
* @return the version number of this installed code
*/
public final long getVersion() {
return version;
}
/**
* Returns the name of this installed code.
*/
public String getName() {
return name;
}
/**
* Returns the start address of this installed code if it is {@linkplain #isValid() valid}, 0
* otherwise.
*/
public long getStart() {
return 0;
}
/**
* @return true if the code represented by this object is still valid for invocation, false
* otherwise (may happen due to deopt, etc.)
*/
public boolean isValid() {
return [MASK] != 0;
}
/**
* @return true if this object still points to installed code
*/
public boolean isAlive() {
return address != 0;
}
/**
* Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise.
*/
public byte[] getCode() {
return null;
}
/**
* Equivalent to calling {@link #invalidate(boolean)} with a {@code true} argument.
*/
public void invalidate() {
invalidate(true);
}
/**
* Invalidates this installed code such that any subsequent
* {@linkplain #executeVarargs(Object...) invocation} will throw an
* {@link InvalidInstalledCodeException}.
*
* If this installed code is already {@linkplain #isValid() invalid}, this method has no effect.
* A subsequent call to {@link #isAlive()} or {@link #isValid()} on this object will return
* {@code false}.
*
* @param deoptimize if {@code true}, all existing invocations will be immediately deoptimized.
* If {@code false}, any existing invocation will continue until it completes or
* there is a subsequent call to this method with {@code deoptimize == true} before
* the invocation completes.
*/
public void invalidate(boolean deoptimize) {
throw new UnsupportedOperationException();
}
/**
* Executes the installed code with a variable number of arguments.
*
* @param args the array of object arguments
* @return the value returned by the executed code
*/
@SuppressWarnings("unused")
public Object executeVarargs(Object... args) throws InvalidInstalledCodeException {
throw new UnsupportedOperationException();
}
}
|
entryPoint
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
[MASK] (createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
[MASK] (createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
[MASK] (createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
[MASK] (createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
[MASK] (
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
[MASK] (
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
[MASK] (createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
[MASK] (createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
[MASK] (Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
[MASK] (Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
[MASK] (Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
[MASK] (Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
[MASK] (Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
[MASK] (Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
[MASK] (Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
[MASK] (MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
[MASK] (MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
assertThat
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()). [MASK] (mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()). [MASK] (method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()). [MASK] (uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()). [MASK] (path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()). [MASK] (headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()). [MASK] (value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()). [MASK] (pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()). [MASK] (cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)). [MASK] (result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)). [MASK] (result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)). [MASK] (result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)). [MASK] (result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)). [MASK] (result);
}
}
|
isSameAs
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var [MASK] = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex( [MASK] ), equalTo("index-000003"));
}
{
var [MASK] = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex( [MASK] ), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
names
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool. [MASK] ;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private [MASK] threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock( [MASK] .class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
ThreadPool
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void [MASK] () {
MultiValueMap<String, HttpCookie> [MASK] = mock();
given(mockRequest. [MASK] ()).willReturn( [MASK] );
assertThat(wrapper. [MASK] ()).isSameAs( [MASK] );
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
cookies
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core. [MASK] ;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMono [MASK] () {
Mono<String> result = Mono.just("foo");
[MASK] <String> reference = new [MASK] <>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFlux [MASK] () {
Flux<String> result = Flux.just("foo");
[MASK] <String> reference = new [MASK] <>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
ParameterizedTypeReference
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return [MASK] ;
}
private String [MASK] ;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String [MASK] ) {
this.name = name;
this. [MASK] = [MASK] ;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append( [MASK] ).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
keyword
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.Coded [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io. [MASK] input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io. [MASK] input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io. [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.Coded [MASK] input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.Coded [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.Coded [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.Coded [MASK] input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
InputStream
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient. [MASK] ()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient). [MASK] ();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient). [MASK] ();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
prepareAliases
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions. [MASK] ;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
[MASK] (wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
[MASK] (wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
[MASK] (wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
[MASK] (wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
[MASK] (wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
[MASK] (wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
[MASK] (wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
[MASK] (wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
[MASK] (wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
[MASK] (wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
[MASK] (wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
[MASK] (wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
[MASK] (wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
[MASK] (wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
[MASK] (wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
[MASK] (wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
assertThat
|
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.redis.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind. [MASK] ;
import java.io.UncheckedIOException;
public class JsonEncoder
{
private final [MASK] objectMapper = new [MASK] ();
public String toString(Object o)
{
try {
return objectMapper.writeValueAsString(o);
}
catch (JsonProcessingException e) {
throw new UncheckedIOException(e);
}
}
}
|
ObjectMapper
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util. [MASK] ;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
[MASK] .emptyMap(),
[MASK] .singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
[MASK] .singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
[MASK] .emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
[MASK] .emptyMap(),
[MASK] .emptyMap(),
[MASK] .singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
[MASK] .singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState( [MASK] .emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState( [MASK] .emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo( [MASK] .singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState( [MASK] .singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
[MASK] .singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
[MASK] .singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo( [MASK] .singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, [MASK] .emptyMap(), [MASK] .emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
Collections
|
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io. [MASK] .core.protocol.transaction;
import io. [MASK] .core.protocol.MessageType;
import io. [MASK] .core.rpc.RpcContext;
/**
* The type Global lock query request.
*
* @author slievrly
*/
public class GlobalLockQueryRequest extends BranchRegisterRequest {
@Override
public short getTypeCode() {
return MessageType.TYPE_GLOBAL_LOCK_QUERY;
}
@Override
public AbstractTransactionResponse handle(RpcContext rpcContext) {
return handler.handle(this, rpcContext);
}
}
|
seata
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
[MASK] ("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && ! [MASK] .equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals( [MASK] )){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum. [MASK] .getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
PRIMARY_KEY
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf. [MASK] {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf. [MASK] e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf. [MASK] (
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf. [MASK] {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf. [MASK] e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf. [MASK] {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
InvalidProtocolBufferException
|
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.sql.parser.rules;
import org.jkiss.dbeaver.model.sql.parser.tokens.SQLControlToken;
import org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss.dbeaver.model.text.parser.TP [MASK] Scanner;
import org.jkiss.dbeaver.model.text.parser.rules.EndOfLineRule;
public class SQLCommandRule extends EndOfLineRule {
public SQLCommandRule(String commandPrefix, SQLCommandHandlerDescriptor controlCommand, SQLControlToken controlToken) {
super(commandPrefix + controlCommand.getId() + ' ', controlToken);
super.fExcludeLineDelimiter = true;
}
protected boolean sequenceDetected(TP [MASK] Scanner scanner, char[] sequence, boolean eofAllowed) {
for (int i = 1; i < sequence.length; i++) {
int c = scanner.read();
char seqChar = sequence[i];
boolean validChar = (seqChar == ' ' && [MASK] .isWhitespace(c)) || [MASK] .toUpperCase(c) == [MASK] .toUpperCase(seqChar);
if (!validChar) {
// Non-matching character detected, rewind the scanner back to the start.
// Do not unread the first character.
scanner.unread();
for (int j = i - 1; j > 0; j--) {
scanner.unread();
}
return false;
}
}
return true;
}
}
|
Character
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()). [MASK] (method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()). [MASK] (uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()). [MASK] (path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()). [MASK] (headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)). [MASK] (Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)). [MASK] (Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()). [MASK] (value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)). [MASK] (value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()). [MASK] (pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()). [MASK] (cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)). [MASK] (result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)). [MASK] (result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)). [MASK] (result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)). [MASK] (result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)). [MASK] (result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
willReturn
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String [MASK] (TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", [MASK] (tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", [MASK] (tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
buildIndexScript
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest [MASK] = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper( [MASK] );
@Test
void request() {
assertThat(wrapper.request()).isSameAs( [MASK] );
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given( [MASK] .method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given( [MASK] .uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given( [MASK] .path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given( [MASK] .headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given( [MASK] .attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given( [MASK] .queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given( [MASK] .queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given( [MASK] .pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given( [MASK] .pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given( [MASK] .cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given( [MASK] .body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given( [MASK] .bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given( [MASK] .bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given( [MASK] .bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given( [MASK] .bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
mockRequest
|
package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config;
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
import io.swagger.v3.oas.annotations.media. [MASK] ;
import lombok.Data;
import java.time.LocalDateTime;
@ [MASK] (description = "管理后台 - 文件配置 Response VO")
@Data
public class FileConfigRespVO {
@ [MASK] (description = "编号", requiredMode = [MASK] .RequiredMode.REQUIRED, example = "1")
private Long id;
@ [MASK] (description = "配置名", requiredMode = [MASK] .RequiredMode.REQUIRED, example = "S3 - 阿里云")
private String name;
@ [MASK] (description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = [MASK] .RequiredMode.REQUIRED, example = "1")
private Integer storage;
@ [MASK] (description = "是否为主配置", requiredMode = [MASK] .RequiredMode.REQUIRED, example = "true")
private Boolean master;
@ [MASK] (description = "存储配置", requiredMode = [MASK] .RequiredMode.REQUIRED)
private FileClientConfig config;
@ [MASK] (description = "备注", example = "我是备注")
private String remark;
@ [MASK] (description = "创建时间", requiredMode = [MASK] .RequiredMode.REQUIRED)
private LocalDateTime createTime;
}
|
Schema
|
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver. [MASK] .sql.parser.rules;
import org.jkiss.dbeaver. [MASK] .sql.parser.tokens.SQLControlToken;
import org.jkiss.dbeaver. [MASK] .sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss.dbeaver. [MASK] .text.parser.TPCharacterScanner;
import org.jkiss.dbeaver. [MASK] .text.parser.rules.EndOfLineRule;
public class SQLCommandRule extends EndOfLineRule {
public SQLCommandRule(String commandPrefix, SQLCommandHandlerDescriptor controlCommand, SQLControlToken controlToken) {
super(commandPrefix + controlCommand.getId() + ' ', controlToken);
super.fExcludeLineDelimiter = true;
}
protected boolean sequenceDetected(TPCharacterScanner scanner, char[] sequence, boolean eofAllowed) {
for (int i = 1; i < sequence.length; i++) {
int c = scanner.read();
char seqChar = sequence[i];
boolean validChar = (seqChar == ' ' && Character.isWhitespace(c)) || Character.toUpperCase(c) == Character.toUpperCase(seqChar);
if (!validChar) {
// Non-matching character detected, rewind the scanner back to the start.
// Do not unread the first character.
scanner.unread();
for (int j = i - 1; j > 0; j--) {
scanner.unread();
}
return false;
}
}
return true;
}
}
|
model
|
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.sql.parser.rules;
import org.jkiss.dbeaver.model.sql.parser.tokens.SQLControlToken;
import org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner;
import org.jkiss.dbeaver.model.text.parser.rules.EndOfLineRule;
public class SQLCommandRule extends EndOfLineRule {
public SQLCommandRule(String commandPrefix, SQLCommandHandlerDescriptor controlCommand, SQLControlToken controlToken) {
super(commandPrefix + controlCommand.getId() + ' ', controlToken);
super.fExcludeLineDelimiter = true;
}
protected boolean sequenceDetected(TPCharacterScanner [MASK] , char[] sequence, boolean eofAllowed) {
for (int i = 1; i < sequence.length; i++) {
int c = [MASK] .read();
char seqChar = sequence[i];
boolean validChar = (seqChar == ' ' && Character.isWhitespace(c)) || Character.toUpperCase(c) == Character.toUpperCase(seqChar);
if (!validChar) {
// Non-matching character detected, rewind the [MASK] back to the start.
// Do not unread the first character.
[MASK] .unread();
for (int j = i - 1; j > 0; j--) {
[MASK] .unread();
}
return false;
}
}
return true;
}
}
|
scanner
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive. [MASK] .server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive. [MASK] .BodyExtractor;
import org.springframework.web.reactive. [MASK] .BodyExtractors;
import org.springframework.web.reactive. [MASK] .server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
function
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite [MASK] ) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry [MASK] ) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) [MASK] );
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
registry
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> [MASK] = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
[MASK] .onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> [MASK] = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
[MASK] .onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
actionListener
|
package cn.iocoder.yudao.module.product.convert.sku;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 商品 SKU Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductSkuConvert {
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
/**
* 获得 SPU 的库存变化 Map
*
* @param items SKU 库存变化
* @param skus SKU 列表
* @return SPU 的库存变化 Map
*/
default Map<Long, Integer> convertSpuStockMap(List<ProductSkuUpdateStockReqDTO.Item> items,
List<ProductSkuDO> skus) {
Map<Long, Long> skuIdAndSpuIdMap = convertMap(skus, ProductSkuDO::getId, ProductSkuDO::getSpuId); // SKU 与 SKU 编号的 Map 关系
Map<Long, Integer> [MASK] AndStockMap = new HashMap<>(); // SPU 的库存变化 Map 关系
items.forEach(item -> {
Long [MASK] = skuIdAndSpuIdMap.get(item.getId());
if ( [MASK] == null) {
return;
}
Integer stock = [MASK] AndStockMap.getOrDefault( [MASK] , 0) + item.getIncrCount();
[MASK] AndStockMap.put( [MASK] , stock);
});
return [MASK] AndStockMap;
}
default String buildPropertyKey(ProductSkuDO bean) {
if (CollUtil.isEmpty(bean.getProperties())) {
return StrUtil.EMPTY;
}
List<ProductSkuDO.Property> properties = new ArrayList<>(bean.getProperties());
properties.sort(Comparator.comparing(ProductSkuDO.Property::getValueId));
return properties.stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining());
}
}
|
spuId
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return [MASK] (tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join( [MASK] (tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String [MASK] (TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
buildDropIndex
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch. [MASK] .core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch. [MASK] .core.ml.notifications.NotificationsIndex;
import org.elasticsearch. [MASK] .core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
" [MASK] .ml.version",
Map.of(
" [MASK] .ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
" [MASK] .ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
" [MASK] .ml.version",
Map.of(
" [MASK] .ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
" [MASK] .ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
" [MASK] .ml.version",
Map.of(
" [MASK] .ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
" [MASK] .ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
xpack
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase. [MASK] ;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
[MASK] (counter.sum(), numberOfIncrements * numberOfThreads);
[MASK] (counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
[MASK] (counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> [MASK] (counter.sum(), 0));
}
}
|
assertEquals
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health. [MASK] ;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener< [MASK] > actionListener = (ActionListener< [MASK] >) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new [MASK] ());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
ClusterHealthResponse
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util. [MASK] .ExecutorService;
import java.util. [MASK] .Executors;
import java.util. [MASK] .TimeUnit;
import java.util. [MASK] .atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals(counter.sum(), 0));
}
}
|
concurrent
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
[MASK] ();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
[MASK] ();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
[MASK] ();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
onChanged
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest. [MASK] .contains;
import static org.hamcrest. [MASK] .empty;
import static org.hamcrest. [MASK] .equalTo;
import static org.mockito.Argument [MASK] .any;
import static org.mockito.Argument [MASK] .same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
Matchers
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder(). [MASK] (prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder(). [MASK] (this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder [MASK] (com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return [MASK] ((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super. [MASK] (other);
return this;
}
}
public Builder [MASK] (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder [MASK] (
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
[MASK] (parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
mergeFrom
|
package cn.iocoder.yudao. [MASK] .product.convert.sku;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao. [MASK] .product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao. [MASK] .product.dal.dataobject.sku.ProductSkuDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 商品 SKU Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductSkuConvert {
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
/**
* 获得 SPU 的库存变化 Map
*
* @param items SKU 库存变化
* @param skus SKU 列表
* @return SPU 的库存变化 Map
*/
default Map<Long, Integer> convertSpuStockMap(List<ProductSkuUpdateStockReqDTO.Item> items,
List<ProductSkuDO> skus) {
Map<Long, Long> skuIdAndSpuIdMap = convertMap(skus, ProductSkuDO::getId, ProductSkuDO::getSpuId); // SKU 与 SKU 编号的 Map 关系
Map<Long, Integer> spuIdAndStockMap = new HashMap<>(); // SPU 的库存变化 Map 关系
items.forEach(item -> {
Long spuId = skuIdAndSpuIdMap.get(item.getId());
if (spuId == null) {
return;
}
Integer stock = spuIdAndStockMap.getOrDefault(spuId, 0) + item.getIncrCount();
spuIdAndStockMap.put(spuId, stock);
});
return spuIdAndStockMap;
}
default String buildPropertyKey(ProductSkuDO bean) {
if (CollUtil.isEmpty(bean.getProperties())) {
return StrUtil.EMPTY;
}
List<ProductSkuDO.Property> properties = new ArrayList<>(bean.getProperties());
properties.sort(Comparator.comparing(ProductSkuDO.Property::getValueId));
return properties.stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining());
}
}
|
module
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal. [MASK] ;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private [MASK] clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock( [MASK] .class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
ClusterAdminClient
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3. [MASK]
internalGet [MASK] () {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3. [MASK]
internalGet [MASK] () {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3. [MASK]
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3. [MASK] (
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
FieldAccessorTable
|
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.vm.ci.code;
/**
* Represents a compiled instance of a method. It may have been invalidated or removed in the
* meantime.
*/
public class InstalledCode {
/**
* Address of the entity (e.g., HotSpot {@code nmethod} or {@code RuntimeStub}) representing
* this installed code.
*/
protected long address;
/**
* Address of the entryPoint of this installed code.
*/
protected long entryPoint;
/**
* Counts how often the address field was reassigned.
*/
protected long version;
protected final [MASK] name;
public InstalledCode( [MASK] name) {
this.name = name;
}
/**
* @return the address of entity (e.g., HotSpot {@code nmethod} or {@code RuntimeStub})
* representing this installed code
*/
public long getAddress() {
return address;
}
/**
* @return the address of the normal entry point of the installed code.
*/
public long getEntryPoint() {
return entryPoint;
}
/**
* @return the version number of this installed code
*/
public final long getVersion() {
return version;
}
/**
* Returns the name of this installed code.
*/
public [MASK] getName() {
return name;
}
/**
* Returns the start address of this installed code if it is {@linkplain #isValid() valid}, 0
* otherwise.
*/
public long getStart() {
return 0;
}
/**
* @return true if the code represented by this object is still valid for invocation, false
* otherwise (may happen due to deopt, etc.)
*/
public boolean isValid() {
return entryPoint != 0;
}
/**
* @return true if this object still points to installed code
*/
public boolean isAlive() {
return address != 0;
}
/**
* Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise.
*/
public byte[] getCode() {
return null;
}
/**
* Equivalent to calling {@link #invalidate(boolean)} with a {@code true} argument.
*/
public void invalidate() {
invalidate(true);
}
/**
* Invalidates this installed code such that any subsequent
* {@linkplain #executeVarargs(Object...) invocation} will throw an
* {@link InvalidInstalledCodeException}.
*
* If this installed code is already {@linkplain #isValid() invalid}, this method has no effect.
* A subsequent call to {@link #isAlive()} or {@link #isValid()} on this object will return
* {@code false}.
*
* @param deoptimize if {@code true}, all existing invocations will be immediately deoptimized.
* If {@code false}, any existing invocation will continue until it completes or
* there is a subsequent call to this method with {@code deoptimize == true} before
* the invocation completes.
*/
public void invalidate(boolean deoptimize) {
throw new UnsupportedOperationException();
}
/**
* Executes the installed code with a variable number of arguments.
*
* @param args the array of object arguments
* @return the value returned by the executed code
*/
@SuppressWarnings("unused")
public Object executeVarargs(Object... args) throws InvalidInstalledCodeException {
throw new UnsupportedOperationException();
}
}
|
String
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf. [MASK] registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf. [MASK] ) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf. [MASK] extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf. [MASK] extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf. [MASK] extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf. [MASK] extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
ExtensionRegistryLite
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void [MASK] () {
HttpMethod [MASK] = HttpMethod.POST;
given(mockRequest. [MASK] ()).willReturn( [MASK] );
assertThat(wrapper. [MASK] ()).isSameAs( [MASK] );
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
method
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang. [MASK]
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang. [MASK]
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang. [MASK]
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang. [MASK]
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang. [MASK]
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang. [MASK]
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang. [MASK]
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang. [MASK]
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang. [MASK]
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang. [MASK]
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang. [MASK]
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang. [MASK]
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang. [MASK]
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang. [MASK]
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang. [MASK]
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang. [MASK]
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang. [MASK]
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang. [MASK]
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang. [MASK]
public Builder clone() {
return super.clone();
}
@java.lang. [MASK]
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang. [MASK]
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang. [MASK]
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang. [MASK]
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang. [MASK]
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang. [MASK]
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang. [MASK]
public final boolean isInitialized() {
return true;
}
@java.lang. [MASK]
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang. [MASK]
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang. [MASK]
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang. [MASK]
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang. [MASK]
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang. [MASK]
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang. [MASK]
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
Override
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface [MASK] extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
[MASK] {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass. [MASK] {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
SetCurExpeditionChallengeIdReqOrBuilder
|
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* These authors would like to acknowledge the Spanish Ministry of Industry,
* Tourism and Trade, for the support in the project TSI020301-2008-2
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
* Mobile Dynamic Environments", led by Treelogic
* ( http://www.treelogic.com/ ):
*
* http://www.piramidepse.com/
*/
package com. [MASK] .zxing.oned.rss.expanded;
import com. [MASK] .zxing.BarcodeFormat;
import com. [MASK] .zxing.MultiFormatReader;
import com. [MASK] .zxing.common.AbstractBlackBoxTestCase;
/**
* A test of {@link RSSExpandedReader} against a fixed test set of images.
*/
public final class RSSExpandedBlackBox3TestCase extends AbstractBlackBoxTestCase {
public RSSExpandedBlackBox3TestCase() {
super("src/test/resources/blackbox/rssexpanded-3", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
addTest(117, 117, 0.0f);
addTest(117, 117, 180.0f);
}
}
|
google
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void [MASK] (
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void [MASK] (
com.google.protobuf.ExtensionRegistry registry) {
[MASK] (
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
registerAllExtensions
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOr [MASK] extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOr [MASK] {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOr [MASK] {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.new [MASK] () to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3. [MASK] <?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet. [MASK] unknownFields =
com.google.protobuf.UnknownFieldSet.new [MASK] ();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq. [MASK] .class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public [MASK] new [MASK] ForType() { return new [MASK] (); }
public static [MASK] new [MASK] () {
return DEFAULT_INSTANCE.to [MASK] ();
}
public static [MASK] new [MASK] (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.to [MASK] ().mergeFrom(prototype);
}
@java.lang.Override
public [MASK] to [MASK] () {
return this == DEFAULT_INSTANCE
? new [MASK] () : new [MASK] ().mergeFrom(this);
}
@java.lang.Override
protected [MASK] new [MASK] ForType(
com.google.protobuf.GeneratedMessageV3. [MASK] Parent parent) {
[MASK] builder = new [MASK] (parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class [MASK] extends
com.google.protobuf.GeneratedMessageV3. [MASK] < [MASK] > implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOr [MASK] {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq. [MASK] .class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.new [MASK] ()
private [MASK] () {
maybeForce [MASK] Initialization();
}
private [MASK] (
com.google.protobuf.GeneratedMessageV3. [MASK] Parent parent) {
super(parent);
maybeForce [MASK] Initialization();
}
private void maybeForce [MASK] Initialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseField [MASK] s) {
}
}
@java.lang.Override
public [MASK] clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public [MASK] clone() {
return super.clone();
}
@java.lang.Override
public [MASK] setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public [MASK] clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public [MASK] clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public [MASK] setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public [MASK] addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public [MASK] mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public [MASK] mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public [MASK] mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public [MASK] setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public [MASK] clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final [MASK] setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final [MASK] mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
Builder
|
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss. [MASK] .model.sql.parser.rules;
import org.jkiss. [MASK] .model.sql.parser.tokens.SQLControlToken;
import org.jkiss. [MASK] .model.sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss. [MASK] .model.text.parser.TPCharacterScanner;
import org.jkiss. [MASK] .model.text.parser.rules.EndOfLineRule;
public class SQLCommandRule extends EndOfLineRule {
public SQLCommandRule(String commandPrefix, SQLCommandHandlerDescriptor controlCommand, SQLControlToken controlToken) {
super(commandPrefix + controlCommand.getId() + ' ', controlToken);
super.fExcludeLineDelimiter = true;
}
protected boolean sequenceDetected(TPCharacterScanner scanner, char[] sequence, boolean eofAllowed) {
for (int i = 1; i < sequence.length; i++) {
int c = scanner.read();
char seqChar = sequence[i];
boolean validChar = (seqChar == ' ' && Character.isWhitespace(c)) || Character.toUpperCase(c) == Character.toUpperCase(seqChar);
if (!validChar) {
// Non-matching character detected, rewind the scanner back to the start.
// Do not unread the first character.
scanner.unread();
for (int j = i - 1; j > 0; j--) {
scanner.unread();
}
return false;
}
}
return true;
}
}
|
dbeaver
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this. [MASK] ;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder [MASK] =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, [MASK] , extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this. [MASK] = [MASK] .build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
[MASK] .writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += [MASK] .getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (! [MASK] .equals(other. [MASK] )) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + [MASK] .hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other. [MASK] );
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet [MASK] ) {
return super.setUnknownFields( [MASK] );
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet [MASK] ) {
return super.mergeUnknownFields( [MASK] );
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
unknownFields
|
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* These authors would like to acknowledge the Spanish Ministry of Industry,
* Tourism and Trade, for the support in the project TSI020301-2008-2
* "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
* Mobile Dynamic Environments", led by Treelogic
* ( http://www.treelogic.com/ ):
*
* http://www.piramidepse.com/
*/
package com.google. [MASK] .oned.rss.expanded;
import com.google. [MASK] .BarcodeFormat;
import com.google. [MASK] .MultiFormatReader;
import com.google. [MASK] .common.AbstractBlackBoxTestCase;
/**
* A test of {@link RSSExpandedReader} against a fixed test set of images.
*/
public final class RSSExpandedBlackBox3TestCase extends AbstractBlackBoxTestCase {
public RSSExpandedBlackBox3TestCase() {
super("src/test/resources/blackbox/rssexpanded-3", new MultiFormatReader(), BarcodeFormat.RSS_EXPANDED);
addTest(117, 117, 0.0f);
addTest(117, 117, 180.0f);
}
}
|
zxing
|
/*
* Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.annotation.processing;
/**
* Utility class for assembling {@link [MASK] } objects.
*
* @since 1.6
*/
public class [MASK] s {
// No instances for you.
private [MASK] s() {}
private static class Simple [MASK] implements [MASK] {
private String value;
private String message;
Simple [MASK] (String value, String message) {
if (value == null || message == null)
throw new NullPointerException("Null completion strings not accepted.");
this.value = value;
this.message = message;
}
public String getValue() {
return value;
}
public String getMessage() {
return message;
}
@Override
public String toString() {
return "[\"" + value + "\", \"" + message + "\"]";
}
// Default equals and hashCode are fine.
}
/**
* {@return a completion of the value and message}
*
* @param value the text of the completion
* @param message a message about the completion
*/
public static [MASK] of(String value, String message) {
return new Simple [MASK] (value, message);
}
/**
* {@return a completion of the value and an empty message}
*
* @param value the text of the completion
*/
public static [MASK] of(String value) {
return new Simple [MASK] (value, "");
}
}
|
Completion
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org. [MASK] .web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org. [MASK] .core.ParameterizedTypeReference;
import org. [MASK] .http.HttpCookie;
import org. [MASK] .http.HttpMethod;
import org. [MASK] .http.ReactiveHttpInputMessage;
import org. [MASK] .util.LinkedMultiValueMap;
import org. [MASK] .util.MultiValueMap;
import org. [MASK] .web.reactive.function.BodyExtractor;
import org. [MASK] .web.reactive.function.BodyExtractors;
import org. [MASK] .web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
springframework
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util.concurrent. [MASK] ;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
[MASK] executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
[MASK] executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals(counter.sum(), 0));
}
}
|
ExecutorService
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean [MASK] (final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super. [MASK] (obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields. [MASK] (other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
equals
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable [MASK] = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute( [MASK] );
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable [MASK] = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute( [MASK] );
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals(counter.sum(), 0));
}
}
|
incrementAction
|
package ai. [MASK] .plugin.hive.type;
import ai. [MASK] .spi.enums.EditStatus;
import ai. [MASK] .spi.model.IndexType;
import ai. [MASK] .spi.model.TableIndex;
import ai. [MASK] .spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
chat2db
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if ( [MASK] != 0) {
return [MASK] ;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
[MASK] = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
memoizedHashCode
|
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model.sql.parser.rules;
import org.jkiss.dbeaver.model.sql.parser.tokens.SQLControlToken;
import org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor;
import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner;
import org.jkiss.dbeaver.model.text.parser.rules.EndOfLineRule;
public class SQLCommandRule extends EndOfLineRule {
public SQLCommandRule(String commandPrefix, SQLCommandHandlerDescriptor controlCommand, SQLControlToken controlToken) {
super(commandPrefix + controlCommand.getId() + ' ', controlToken);
super.fExcludeLineDelimiter = true;
}
protected boolean sequenceDetected(TPCharacterScanner scanner, char[] sequence, boolean eofAllowed) {
for (int i = 1; i < sequence.length; i++) {
int c = scanner.read();
char [MASK] = sequence[i];
boolean validChar = ( [MASK] == ' ' && Character.isWhitespace(c)) || Character.toUpperCase(c) == Character.toUpperCase( [MASK] );
if (!validChar) {
// Non-matching character detected, rewind the scanner back to the start.
// Do not unread the first character.
scanner.unread();
for (int j = i - 1; j > 0; j--) {
scanner.unread();
}
return false;
}
}
return true;
}
}
|
seqChar
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq [MASK] ForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq. [MASK] ();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq. [MASK] ()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq [MASK] () {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq [MASK] ForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
getDefaultInstance
|
package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config;
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 文件配置 Response VO")
@Data
public class FileConfigRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode. [MASK] , example = "1")
private Long id;
@Schema(description = "配置名", requiredMode = Schema.RequiredMode. [MASK] , example = "S3 - 阿里云")
private String name;
@Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode. [MASK] , example = "1")
private Integer storage;
@Schema(description = "是否为主配置", requiredMode = Schema.RequiredMode. [MASK] , example = "true")
private Boolean master;
@Schema(description = "存储配置", requiredMode = Schema.RequiredMode. [MASK] )
private FileClientConfig config;
@Schema(description = "备注", example = "我是备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode. [MASK] )
private LocalDateTime createTime;
}
|
REQUIRED
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito. [MASK] ;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void [MASK] WithMocks() {
[MASK] (indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
[MASK] (client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
verifyNoMoreInteractions
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService [MASK] = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
[MASK] .execute(incrementAction);
}
//then
[MASK] .awaitTermination(500, TimeUnit.MILLISECONDS);
[MASK] .shutdown();
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService [MASK] = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
[MASK] .execute(incrementAction);
}
//then
[MASK] .awaitTermination(500, TimeUnit.MILLISECONDS);
[MASK] .shutdown();
assertEquals(counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals(counter.sum(), 0));
}
}
|
executorService
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void [MASK] () {
ServerRequest.Headers [MASK] = mock();
given(mockRequest. [MASK] ()).willReturn( [MASK] );
assertThat(wrapper. [MASK] ()).isSameAs( [MASK] );
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
headers
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model. [MASK] ;
import ai.chat2db.spi.model. [MASK] Column;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript( [MASK] tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment( [MASK] tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn( [MASK] tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for ( [MASK] Column column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName( [MASK] tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex( [MASK] tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex( [MASK] tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
TableIndex
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util. [MASK] .Stream;
import static java.util. [MASK] .Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames. [MASK] ().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
stream
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer( [MASK] (new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer( [MASK] (IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer( [MASK] (IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> [MASK] (Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
withResponse
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn [MASK] : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank( [MASK] .getColumnName())) {
script.append("`").append( [MASK] .getColumnName()).append("`");
if (!StringUtils.isBlank( [MASK] .getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append( [MASK] .getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
column
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata. [MASK] ;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, [MASK] > legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static [MASK] createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return [MASK] .builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
IndexTemplateMetadata
|
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.api. [MASK] .register.impl;
import com.alibaba.nacos.api. [MASK] .constant.AbilityKey;
import com.alibaba.nacos.api. [MASK] .register.AbstractAbilityRegistry;
import java.util.Map;
/**
* It is used to register cluster client abilities.
*
* @author Daydreamer
**/
public class ClusterClientAbilities extends AbstractAbilityRegistry {
private static final ClusterClientAbilities INSTANCE = new ClusterClientAbilities();
{
/*
* example:
* There is a function named "compression".
* The key is from <p>AbilityKey</p>, the value is whether turn on.
*
* You can add a new public field in <p>AbilityKey</p> like:
* <code>DATA_COMPRESSION("compression", "description about this [MASK] ")</code>
*
* And then you need to declare whether turn on in the [MASK] table, you can:
* <code>supportedAbilities.put(AbilityKey.DATA_COMPRESSION, true);</code> means that current client support compression.
*
*/
// put [MASK] here, which you want current client supports
}
/**
* get static [MASK] current cluster client supports.
*
* @return static [MASK]
*/
public static Map<AbilityKey, Boolean> getStaticAbilities() {
return INSTANCE.getSupportedAbilities();
}
}
|
ability
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void [MASK] () {
String name = "foo";
String value = "bar";
given(mockRequest. [MASK] (name)).willReturn(value);
assertThat(wrapper. [MASK] (name)).isEqualTo(value);
}
@Test
void [MASK] s() {
Map<String, String> [MASK] s = Collections.singletonMap("foo", "bar");
given(mockRequest. [MASK] s()).willReturn( [MASK] s);
assertThat(wrapper. [MASK] s()).isSameAs( [MASK] s);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
pathVariable
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener. [MASK] (any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener). [MASK] (any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener). [MASK] (any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
delegateFailureAndWrap
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
[MASK] path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
[MASK] name = "foo";
[MASK] value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
[MASK] name = "foo";
[MASK] value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap< [MASK] , [MASK] > value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
[MASK] name = "foo";
[MASK] value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map< [MASK] , [MASK] > pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap< [MASK] , HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono< [MASK] > result = Mono.just("foo");
BodyExtractor<Mono< [MASK] >, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono( [MASK] .class);
given(mockRequest.body(extractor)).willReturn(result);
assertThat(wrapper.body(extractor)).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono< [MASK] > result = Mono.just("foo");
given(mockRequest.bodyToMono( [MASK] .class)).willReturn(result);
assertThat(wrapper.bodyToMono( [MASK] .class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono< [MASK] > result = Mono.just("foo");
ParameterizedTypeReference< [MASK] > reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux< [MASK] > result = Flux.just("foo");
given(mockRequest.bodyToFlux( [MASK] .class)).willReturn(result);
assertThat(wrapper.bodyToFlux( [MASK] .class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux< [MASK] > result = Flux.just("foo");
ParameterizedTypeReference< [MASK] > reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
String
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache. [MASK] .test.it.sql.parser.internal.cases.parser.jaxb.statement.dcl;
import lombok.Getter;
import org.apache. [MASK] .test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.column.ExpectedColumn;
import org.apache. [MASK] .test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedSimpleTable;
import org.apache. [MASK] .test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import javax.xml.bind.annotation.XmlElement;
import java.util.LinkedList;
import java.util.List;
/**
* Grant statement test case.
*/
@Getter
public final class GrantStatementTestCase extends SQLParserTestCase {
@XmlElement(name = "table")
private final List<ExpectedSimpleTable> tables = new LinkedList<>();
@XmlElement(name = "column")
private final List<ExpectedColumn> columns = new LinkedList<>();
}
|
shardingsphere
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void [MASK] (List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
[MASK] (Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
[MASK] (Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
[MASK] (
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
assertMlStateWriteAliasAddedToMostRecentMlStateIndex
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias. [MASK] ;
import org.elasticsearch.action.admin.indices.alias.Indices [MASK] esRequest;
import org.elasticsearch.action.admin.indices.alias.Indices [MASK] esRequest. [MASK] Actions;
import org.elasticsearch.action.admin.indices.alias.Indices [MASK] esRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.Indices [MASK] esResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata. [MASK] Metadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAnd [MASK] Tests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<Indices [MASK] esRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepare [MASK] es()).thenReturn(new Indices [MASK] esRequestBuilder(client));
doAnswer(withResponse(Indices [MASK] esResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(Indices [MASK] esResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<Indices [MASK] esResponse> actionListener = (ActionListener<Indices [MASK] esResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(Indices [MASK] esResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(Indices [MASK] esRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAnd [MASK] .installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAnd [MASK] .installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAnd [MASK] .installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAnd [MASK] IfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new [MASK] (TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWrite [MASK] AlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWith [MASK] (indexName)));
createIndexAnd [MASK] IfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] AlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWrite [MASK] AlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] AlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWrite [MASK] AlreadyExists("test-000007");
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] AlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWrite [MASK] AlreadyExists("dummy-index");
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] AlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWith [MASK] (LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAnd [MASK] IfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepare [MASK] es();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
Indices [MASK] esRequest indices [MASK] esRequest = aliasesRequestCaptor.getValue();
assertThat(
indices [MASK] esRequest.get [MASK] Actions(),
contains(
[MASK] Actions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
[MASK] Actions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWrite [MASK] AddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAnd [MASK] Tests::createIndexMetadata))
);
createIndexAnd [MASK] IfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepare [MASK] es();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
Indices [MASK] esRequest indices [MASK] esRequest = aliasesRequestCaptor.getValue();
assertThat(
indices [MASK] esRequest.get [MASK] Actions(),
contains( [MASK] Actions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] DoesNotExistButInitialStateIndexExists() {
assertMlStateWrite [MASK] AddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] DoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWrite [MASK] AddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] DoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWrite [MASK] AddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAnd [MASK] IfNecessary_Write [MASK] DoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAnd [MASK] IfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new [MASK] (TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAnd [MASK] .INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAnd [MASK] .latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAnd [MASK] .latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAnd [MASK] .indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAnd [MASK] .indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAnd [MASK] .indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAnd [MASK] IfNecessary(ClusterState clusterState) {
MlIndexAnd [MASK] .createIndexAnd [MASK] IfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWith [MASK] (String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean with [MASK] ) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (with [MASK] ) {
builder.put [MASK] ( [MASK] Metadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
Alias
|
package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config;
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 文件配置 Response VO")
@Data
public class FileConfigRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, [MASK] = "1")
private Long id;
@Schema(description = "配置名", requiredMode = Schema.RequiredMode.REQUIRED, [MASK] = "S3 - 阿里云")
private String name;
@Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, [MASK] = "1")
private Integer storage;
@Schema(description = "是否为主配置", requiredMode = Schema.RequiredMode.REQUIRED, [MASK] = "true")
private Boolean master;
@Schema(description = "存储配置", requiredMode = Schema.RequiredMode.REQUIRED)
private FileClientConfig config;
@Schema(description = "备注", [MASK] = "我是备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}
|
example
|
package cn.iocoder.yudao.module.infra.controller.admin.file.vo.config;
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 文件配置 Response VO")
@Data
public class FileConfigRespVO {
@Schema(description = "编号", requiredMode = Schema. [MASK] .REQUIRED, example = "1")
private Long id;
@Schema(description = "配置名", requiredMode = Schema. [MASK] .REQUIRED, example = "S3 - 阿里云")
private String name;
@Schema(description = "存储器,参见 FileStorageEnum 枚举类", requiredMode = Schema. [MASK] .REQUIRED, example = "1")
private Integer storage;
@Schema(description = "是否为主配置", requiredMode = Schema. [MASK] .REQUIRED, example = "true")
private Boolean master;
@Schema(description = "存储配置", requiredMode = Schema. [MASK] .REQUIRED)
private FileClientConfig config;
@Schema(description = "备注", example = "我是备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema. [MASK] .REQUIRED)
private LocalDateTime createTime;
}
|
RequiredMode
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest [MASK] = aliasesRequestCaptor.getValue();
assertThat(
[MASK] .getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest [MASK] = aliasesRequestCaptor.getValue();
assertThat(
[MASK] .getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
indicesAliasesRequest
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_ [MASK] AccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_ [MASK] AccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor [MASK] ,
java.lang.Object value) {
return super.setField( [MASK] , value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor [MASK] ) {
return super.clearField( [MASK] );
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor [MASK] ,
int index, java.lang.Object value) {
return super.setRepeatedField( [MASK] , index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor [MASK] ,
java.lang.Object value) {
return super.addRepeatedField( [MASK] , value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_ [MASK] AccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_ [MASK] AccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
field
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors. [MASK] field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors. [MASK] field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors. [MASK] field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors. [MASK] field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
FieldDescriptor
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
. [MASK] (
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client). [MASK] (same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client). [MASK] (same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
execute
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return [MASK] ;
}
public void setIndexType(IndexType [MASK] ) {
this. [MASK] = [MASK] ;
}
private IndexType [MASK] ;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this. [MASK] = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
indexType
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
[MASK] script = new [MASK] ();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
[MASK] script = new [MASK] ();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
StringBuilder
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class [MASK] {
private [MASK] () {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto. [MASK] .internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto. [MASK] .internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto. [MASK] .internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto. [MASK] .internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto. [MASK] .internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto. [MASK] .SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
SetCurExpeditionChallengeIdReqOuterClass
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq. [MASK] () to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet. [MASK] ();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder [MASK] ForType() { return [MASK] (); }
public static Builder [MASK] () {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder [MASK] (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder [MASK] ForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq. [MASK] ()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
newBuilder
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq [MASK] = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= [MASK] .getId()) return false;
if (!unknownFields.equals( [MASK] .unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message [MASK] ) {
if ( [MASK] instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) [MASK] );
} else {
super.mergeFrom( [MASK] );
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq [MASK] ) {
if ( [MASK] == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if ( [MASK] .getId() != 0) {
setId( [MASK] .getId());
}
this.mergeUnknownFields( [MASK] .unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
other
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org. [MASK] .Matchers.contains;
import static org. [MASK] .Matchers.empty;
import static org. [MASK] .Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
hamcrest
|
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.function.server.support;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.server.ServerRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
class ServerRequestWrapperTests {
private final ServerRequest mockRequest = mock();
private final ServerRequestWrapper wrapper = new ServerRequestWrapper(mockRequest);
@Test
void request() {
assertThat(wrapper.request()).isSameAs(mockRequest);
}
@Test
void method() {
HttpMethod method = HttpMethod.POST;
given(mockRequest.method()).willReturn(method);
assertThat(wrapper.method()).isSameAs(method);
}
@Test
void uri() {
URI uri = URI.create("https://example.com");
given(mockRequest.uri()).willReturn(uri);
assertThat(wrapper.uri()).isSameAs(uri);
}
@Test
void path() {
String path = "/foo/bar";
given(mockRequest.path()).willReturn(path);
assertThat(wrapper.path()).isSameAs(path);
}
@Test
void headers() {
ServerRequest.Headers headers = mock();
given(mockRequest.headers()).willReturn(headers);
assertThat(wrapper.headers()).isSameAs(headers);
}
@Test
void attribute() {
String name = "foo";
String value = "bar";
given(mockRequest.attribute(name)).willReturn(Optional.of(value));
assertThat(wrapper.attribute(name)).contains(value);
}
@Test
void queryParam() {
String name = "foo";
String value = "bar";
given(mockRequest.queryParam(name)).willReturn(Optional.of(value));
assertThat(wrapper.queryParam(name)).contains(value);
}
@Test
void queryParams() {
MultiValueMap<String, String> value = new LinkedMultiValueMap<>();
value.add("foo", "bar");
given(mockRequest.queryParams()).willReturn(value);
assertThat(wrapper.queryParams()).isSameAs(value);
}
@Test
void pathVariable() {
String name = "foo";
String value = "bar";
given(mockRequest.pathVariable(name)).willReturn(value);
assertThat(wrapper.pathVariable(name)).isEqualTo(value);
}
@Test
void pathVariables() {
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
given(mockRequest.pathVariables()).willReturn(pathVariables);
assertThat(wrapper.pathVariables()).isSameAs(pathVariables);
}
@Test
void cookies() {
MultiValueMap<String, HttpCookie> cookies = mock();
given(mockRequest.cookies()).willReturn(cookies);
assertThat(wrapper.cookies()).isSameAs(cookies);
}
@Test
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> [MASK] = BodyExtractors.toMono(String.class);
given(mockRequest.body( [MASK] )).willReturn(result);
assertThat(wrapper.body( [MASK] )).isSameAs(result);
}
@Test
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockRequest.bodyToMono(String.class)).willReturn(result);
assertThat(wrapper.bodyToMono(String.class)).isSameAs(result);
}
@Test
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToMono(reference)).willReturn(result);
assertThat(wrapper.bodyToMono(reference)).isSameAs(result);
}
@Test
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockRequest.bodyToFlux(String.class)).willReturn(result);
assertThat(wrapper.bodyToFlux(String.class)).isSameAs(result);
}
@Test
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockRequest.bodyToFlux(reference)).willReturn(result);
assertThat(wrapper.bodyToFlux(reference)).isSameAs(result);
}
}
|
extractor
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.IntStream;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder [MASK] = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> [MASK] .increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals( [MASK] .sum(), numberOfIncrements * numberOfThreads);
assertEquals( [MASK] .sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder [MASK] = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> IntStream
.range(0, numberOfIncrements)
.forEach((i) -> [MASK] .increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals( [MASK] .sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals( [MASK] .sum(), 0));
}
}
|
counter
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int [MASK] () {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor(). [MASK] ();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields. [MASK] ();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
hashCode
|
package com.baeldung.adder;
import static com.jayway.awaitility.Awaitility.await;
import static junit.framework.TestCase.assertEquals;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream. [MASK] ;
import org.junit.Test;
public class LongAdderUnitTest {
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThem() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> [MASK]
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
assertEquals(counter.sum(), numberOfIncrements * numberOfThreads);
}
@Test
public void givenMultipleThread_whenTheyWriteToSharedLongAdder_thenShouldCalculateSumForThemAndResetAdderAfterward() throws InterruptedException {
//given
LongAdder counter = new LongAdder();
ExecutorService executorService = Executors.newFixedThreadPool(8);
int numberOfThreads = 4;
int numberOfIncrements = 100;
//when
Runnable incrementAction = () -> [MASK]
.range(0, numberOfIncrements)
.forEach((i) -> counter.increment());
for (int i = 0; i < numberOfThreads; i++) {
executorService.execute(incrementAction);
}
//then
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
executorService.shutdown();
assertEquals(counter.sumThenReset(), numberOfIncrements * numberOfThreads);
await().until(() -> assertEquals(counter.sum(), 0));
}
}
|
IntStream
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: SetCurExpeditionChallengeIdReq.proto
package emu.grasscutter.net.proto;
public final class SetCurExpeditionChallengeIdReqOuterClass {
private SetCurExpeditionChallengeIdReqOuterClass() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
registerAllExtensions(
(com.google.protobuf.ExtensionRegistryLite) registry);
}
public interface SetCurExpeditionChallengeIdReqOrBuilder extends
// @@protoc_insertion_point(interface_extends:SetCurExpeditionChallengeIdReq)
com.google.protobuf.MessageOrBuilder {
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
int getId();
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class SetCurExpeditionChallengeIdReq extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:SetCurExpeditionChallengeIdReq)
SetCurExpeditionChallengeIdReqOrBuilder {
private static final long serialVersionUID = 0L;
// Use SetCurExpeditionChallengeIdReq.newBuilder() to construct.
private SetCurExpeditionChallengeIdReq(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private SetCurExpeditionChallengeIdReq() {
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new SetCurExpeditionChallengeIdReq();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private SetCurExpeditionChallengeIdReq(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
com.google.protobuf.UnknownFieldSet.newBuilder();
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
case 32: {
id_ = input.readUInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new com.google.protobuf.InvalidProtocolBufferException(
e).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
public static final int ID_FIELD_NUMBER = 4;
private int id_;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0) {
output.writeUInt32(4, id_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeUInt32Size(4, id_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)) {
return super.equals(obj);
}
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) obj;
if (getId()
!= other.getId()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + getId();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
public Builder toBuilder() {
return this == DEFAULT_INSTANCE
? new Builder() : new Builder().mergeFrom(this);
}
@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent [MASK] ) {
Builder builder = new Builder( [MASK] );
return builder;
}
/**
* <pre>
* CmdId: 20340
* Obf: OMEPMBGNIDB
* </pre>
*
* Protobuf type {@code SetCurExpeditionChallengeIdReq}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:SetCurExpeditionChallengeIdReq)
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReqOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable
.ensureFieldAccessorsInitialized(
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.class, emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.Builder.class);
}
// Construct using emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent [MASK] ) {
super( [MASK] );
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.internal_static_SetCurExpeditionChallengeIdReq_descriptor;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance();
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq build() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq buildPartial() {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq result = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq(this);
result.id_ = id_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) {
return mergeFrom((emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq other) {
if (other == emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq.getDefaultInstance()) return this;
if (other.getId() != 0) {
setId(other.getId());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int id_ ;
/**
* <code>uint32 id = 4;</code>
* @return The id.
*/
@java.lang.Override
public int getId() {
return id_;
}
/**
* <code>uint32 id = 4;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(int value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>uint32 id = 4;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:SetCurExpeditionChallengeIdReq)
}
// @@protoc_insertion_point(class_scope:SetCurExpeditionChallengeIdReq)
private static final emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq();
}
public static emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq>
PARSER = new com.google.protobuf.AbstractParser<SetCurExpeditionChallengeIdReq>() {
@java.lang.Override
public SetCurExpeditionChallengeIdReq parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new SetCurExpeditionChallengeIdReq(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<SetCurExpeditionChallengeIdReq> getParserForType() {
return PARSER;
}
@java.lang.Override
public emu.grasscutter.net.proto.SetCurExpeditionChallengeIdReqOuterClass.SetCurExpeditionChallengeIdReq getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_SetCurExpeditionChallengeIdReq_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable;
public static com.google.protobuf.Descriptors.FileDescriptor
getDescriptor() {
return descriptor;
}
private static com.google.protobuf.Descriptors.FileDescriptor
descriptor;
static {
java.lang.String[] descriptorData = {
"\n$SetCurExpeditionChallengeIdReq.proto\"," +
"\n\036SetCurExpeditionChallengeIdReq\022\n\n\002id\030\004" +
" \001(\rB\033\n\031emu.grasscutter.net.protob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_SetCurExpeditionChallengeIdReq_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_SetCurExpeditionChallengeIdReq_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_SetCurExpeditionChallengeIdReq_descriptor,
new java.lang.String[] { "Id", });
}
// @@protoc_insertion_point(outer_class_scope)
}
|
parent
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index. [MASK] ;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9( [MASK] .V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9( [MASK] .V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
IndexVersions
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal. [MASK] ;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private [MASK] indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock( [MASK] .class);
when(indicesAdminClient.prepareCreate(FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareCreate(FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
IndicesAdminClient
|
package ai.chat2db.plugin.hive.type;
import ai.chat2db.spi.enums.EditStatus;
import ai.chat2db.spi.model.IndexType;
import ai.chat2db.spi.model.TableIndex;
import ai.chat2db.spi.model.TableIndexColumn;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
public enum HiveIndexTypeEnum {
PRIMARY_KEY("Primary", "PRIMARY KEY"),
NORMAL("Normal", "INDEX"),
UNIQUE("Unique", "UNIQUE INDEX"),
FULLTEXT("Fulltext", "FULLTEXT INDEX"),
SPATIAL("Spatial", "SPATIAL INDEX");
public String getName() {
return name;
}
private String name;
public String getKeyword() {
return keyword;
}
private String keyword;
public IndexType getIndexType() {
return indexType;
}
public void setIndexType(IndexType indexType) {
this.indexType = indexType;
}
private IndexType indexType;
HiveIndexTypeEnum(String name, String keyword) {
this.name = name;
this.keyword = keyword;
this.indexType = new IndexType(name);
}
public static HiveIndexTypeEnum getByType(String type) {
for (HiveIndexTypeEnum value : HiveIndexTypeEnum.values()) {
if (value.name.equalsIgnoreCase(type)) {
return value;
}
}
return null;
}
public String buildIndexScript(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append(keyword).append(" ");
script.append(buildIndexName(tableIndex)).append(" ");
script.append(buildIndexColumn(tableIndex)).append(" ");
script.append(buildIndexComment(tableIndex)).append(" ");
return script.toString();
}
private String buildIndexComment(TableIndex tableIndex) {
if(StringUtils.isBlank(tableIndex.getComment())){
return "";
}else {
return StringUtils.join("COMMENT '",tableIndex.getComment(),"'");
}
}
private String buildIndexColumn(TableIndex tableIndex) {
StringBuilder script = new StringBuilder();
script.append("(");
for (TableIndexColumn column : tableIndex.getColumnList()) {
if(StringUtils.isNotBlank(column.getColumnName())) {
script.append("`").append(column.getColumnName()).append("`");
if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {
script.append(" ").append(column.getAscOrDesc());
}
script.append(",");
}
}
script.deleteCharAt(script.length() - 1);
script.append(")");
return script.toString();
}
private String buildIndexName(TableIndex tableIndex) {
if(this.equals(PRIMARY_KEY)){
return "";
}else {
return "`"+tableIndex.getName()+"`";
}
}
public String buildModifyIndex(TableIndex tableIndex) {
if (EditStatus.DELETE.name().equals(tableIndex. [MASK] ())) {
return buildDropIndex(tableIndex);
}
if (EditStatus.MODIFY.name().equals(tableIndex. [MASK] ())) {
return StringUtils.join(buildDropIndex(tableIndex),",\n", "ADD ", buildIndexScript(tableIndex));
}
if (EditStatus.ADD.name().equals(tableIndex. [MASK] ())) {
return StringUtils.join("ADD ", buildIndexScript(tableIndex));
}
return "";
}
private String buildDropIndex(TableIndex tableIndex) {
if (HiveIndexTypeEnum.PRIMARY_KEY.getName().equals(tableIndex.getType())) {
return StringUtils.join("DROP PRIMARY KEY");
}
return StringUtils.join("DROP INDEX `", tableIndex.getOldName(),"`");
}
public static List<IndexType> getIndexTypes() {
return Arrays.asList(HiveIndexTypeEnum.values()).stream().map(HiveIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList());
}
}
|
getEditStatus
|
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core.ml.utils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.internal.AdminClient;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.ClusterAdminClient;
import org.elasticsearch.client.internal.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.AliasMetadata;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexTemplateMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.indices.TestIndexNameExpressionResolver;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.junit.After;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.stubbing.Answer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MlIndexAndAliasTests extends ESTestCase {
private static final String TEST_INDEX_PREFIX = "test";
private static final String TEST_INDEX_ALIAS = "test-alias";
private static final String LEGACY_INDEX_WITHOUT_SUFFIX = TEST_INDEX_PREFIX;
private static final String FIRST_CONCRETE_INDEX = "test-000001";
private static final int TEST_TEMPLATE_VERSION = 12345678;
private ThreadPool threadPool;
private IndicesAdminClient indicesAdminClient;
private ClusterAdminClient clusterAdminClient;
private AdminClient adminClient;
private Client client;
private ActionListener<Boolean> listener;
private ArgumentCaptor<CreateIndexRequest> createRequestCaptor;
private ArgumentCaptor<IndicesAliasesRequest> aliasesRequestCaptor;
@SuppressWarnings("unchecked")
@Before
public void setUpMocks() {
threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
indicesAdminClient = mock(IndicesAdminClient.class);
when(indicesAdminClient. [MASK] (FIRST_CONCRETE_INDEX)).thenReturn(
new CreateIndexRequestBuilder(client, FIRST_CONCRETE_INDEX)
);
doAnswer(withResponse(new CreateIndexResponse(true, true, FIRST_CONCRETE_INDEX))).when(indicesAdminClient).create(any(), any());
when(indicesAdminClient.prepareAliases()).thenReturn(new IndicesAliasesRequestBuilder(client));
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).aliases(any(), any());
doAnswer(withResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS)).when(indicesAdminClient).putTemplate(any(), any());
clusterAdminClient = mock(ClusterAdminClient.class);
doAnswer(invocationOnMock -> {
ActionListener<ClusterHealthResponse> actionListener = (ActionListener<ClusterHealthResponse>) invocationOnMock
.getArguments()[1];
actionListener.onResponse(new ClusterHealthResponse());
return null;
}).when(clusterAdminClient).health(any(ClusterHealthRequest.class), any(ActionListener.class));
adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
when(client.admin()).thenReturn(adminClient);
doAnswer(invocationOnMock -> {
ActionListener<IndicesAliasesResponse> actionListener = (ActionListener<IndicesAliasesResponse>) invocationOnMock
.getArguments()[2];
actionListener.onResponse(IndicesAliasesResponse.ACKNOWLEDGED_NO_ERRORS);
return null;
}).when(client)
.execute(
same(TransportPutComposableIndexTemplateAction.TYPE),
any(TransportPutComposableIndexTemplateAction.Request.class),
any(ActionListener.class)
);
listener = mock(ActionListener.class);
when(listener.delegateFailureAndWrap(any())).thenCallRealMethod();
createRequestCaptor = ArgumentCaptor.forClass(CreateIndexRequest.class);
aliasesRequestCaptor = ArgumentCaptor.forClass(IndicesAliasesRequest.class);
}
@After
public void verifyNoMoreInteractionsWithMocks() {
verifyNoMoreInteractions(indicesAdminClient, listener);
}
public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createLegacyIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)
)
),
Collections.emptyMap()
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() {
ClusterState clusterState = createClusterState(
Collections.emptyMap(),
Collections.emptyMap(),
Collections.singletonMap(
NotificationsIndex.NOTIFICATIONS_INDEX,
createComposableIndexTemplateMetaData(
NotificationsIndex.NOTIFICATIONS_INDEX,
Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX),
TEST_TEMPLATE_VERSION
)
)
);
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
verify(listener).onResponse(true);
verifyNoMoreInteractions(client);
}
public void testInstallIndexTemplateIfRequired() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(
NotificationsIndex.NOTIFICATIONS_INDEX,
"/ml/notifications_index_template.json",
TEST_TEMPLATE_VERSION,
"xpack.ml.version",
Map.of(
"xpack.ml.version.id",
String.valueOf(TEST_TEMPLATE_VERSION),
"xpack.ml.notifications.mappings",
NotificationsIndex.mapping()
)
);
MlIndexAndAlias.installIndexTemplateIfRequired(
clusterState,
client,
notificationsTemplate,
TimeValue.timeValueMinutes(1),
listener
);
InOrder inOrder = inOrder(client, listener);
inOrder.verify(listener).delegateFailureAndWrap(any());
inOrder.verify(client).execute(same(TransportPutComposableIndexTemplateAction.TYPE), any(), any());
inOrder.verify(listener).onResponse(true);
}
public void testCreateStateIndexAndAliasIfNecessary_CleanState() {
ClusterState clusterState = createClusterState(Collections.emptyMap());
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient). [MASK] (FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
private void assertNoClientInteractionsWhenWriteAliasAlreadyExists(String indexName) {
ClusterState clusterState = createClusterState(Collections.singletonMap(indexName, createIndexMetadataWithAlias(indexName)));
createIndexAndAliasIfNecessary(clusterState);
verify(listener).onResponse(false);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtInitialStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists(FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtSubsequentStateIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("test-000007");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtDummyIndex() {
assertNoClientInteractionsWhenWriteAliasAlreadyExists("dummy-index");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasAlreadyExistsAndPointsAtLegacyStateIndex() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadataWithAlias(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient). [MASK] (FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), empty());
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(
AliasActions.add().alias(TEST_INDEX_ALIAS).index(FIRST_CONCRETE_INDEX).isHidden(true).writeIndex(true),
AliasActions.remove().alias(TEST_INDEX_ALIAS).index(LEGACY_INDEX_WITHOUT_SUFFIX)
)
);
}
private void assertMlStateWriteAliasAddedToMostRecentMlStateIndex(List<String> existingIndexNames, String expectedWriteIndexName) {
ClusterState clusterState = createClusterState(
existingIndexNames.stream().collect(toMap(Function.identity(), MlIndexAndAliasTests::createIndexMetadata))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient).prepareAliases();
inOrder.verify(indicesAdminClient).aliases(aliasesRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
IndicesAliasesRequest indicesAliasesRequest = aliasesRequestCaptor.getValue();
assertThat(
indicesAliasesRequest.getAliasActions(),
contains(AliasActions.add().alias(TEST_INDEX_ALIAS).index(expectedWriteIndexName).isHidden(true).writeIndex(true))
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButInitialStateIndexExists() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList(FIRST_CONCRETE_INDEX), FIRST_CONCRETE_INDEX);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButSubsequentStateIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(Arrays.asList("test-000003", "test-000040", "test-000500"), "test-000500");
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButBothLegacyAndNewIndicesExist() {
assertMlStateWriteAliasAddedToMostRecentMlStateIndex(
Arrays.asList(LEGACY_INDEX_WITHOUT_SUFFIX, "test-000003", "test-000040", "test-000500"),
"test-000500"
);
}
public void testCreateStateIndexAndAliasIfNecessary_WriteAliasDoesNotExistButLegacyStateIndexExists() {
ClusterState clusterState = createClusterState(
Collections.singletonMap(LEGACY_INDEX_WITHOUT_SUFFIX, createIndexMetadata(LEGACY_INDEX_WITHOUT_SUFFIX))
);
createIndexAndAliasIfNecessary(clusterState);
InOrder inOrder = inOrder(indicesAdminClient, listener);
inOrder.verify(indicesAdminClient). [MASK] (FIRST_CONCRETE_INDEX);
inOrder.verify(indicesAdminClient).create(createRequestCaptor.capture(), any());
inOrder.verify(listener).onResponse(true);
CreateIndexRequest createRequest = createRequestCaptor.getValue();
assertThat(createRequest.index(), equalTo(FIRST_CONCRETE_INDEX));
assertThat(createRequest.aliases(), equalTo(Collections.singleton(new Alias(TEST_INDEX_ALIAS).isHidden(true))));
}
public void testIndexNameComparator() {
Comparator<String> comparator = MlIndexAndAlias.INDEX_NAME_COMPARATOR;
assertThat(Stream.of("test-000001").max(comparator).get(), equalTo("test-000001"));
assertThat(Stream.of("test-000002", "test-000001").max(comparator).get(), equalTo("test-000002"));
assertThat(Stream.of("test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of("test-000042", "test-000049", "test-000038").max(comparator).get(), equalTo("test-000049"));
assertThat(Stream.of("test", "test-000003", "test-000040", "test-000500").max(comparator).get(), equalTo("test-000500"));
assertThat(Stream.of(".reindexed-6-test", "test-000042").max(comparator).get(), equalTo("test-000042"));
assertThat(Stream.of(".a-000002", ".b-000001").max(comparator).get(), equalTo(".a-000002"));
}
public void testLatestIndex() {
{
var names = new String[] { "index-000001", "index-000002", "index-000003" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000003"));
}
{
var names = new String[] { "index", "index-000001", "index-000002" };
assertThat(MlIndexAndAlias.latestIndex(names), equalTo("index-000002"));
}
}
public void testIndexIsReadWriteCompatibleInV9() {
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersion.current()));
assertTrue(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_8_0_0));
assertFalse(MlIndexAndAlias.indexIsReadWriteCompatibleInV9(IndexVersions.V_7_17_0));
}
private void createIndexAndAliasIfNecessary(ClusterState clusterState) {
MlIndexAndAlias.createIndexAndAliasIfNecessary(
client,
clusterState,
TestIndexNameExpressionResolver.newInstance(),
TEST_INDEX_PREFIX,
TEST_INDEX_ALIAS,
TimeValue.timeValueSeconds(30),
ActiveShardCount.DEFAULT,
listener
);
}
@SuppressWarnings("unchecked")
private static <Response> Answer<Response> withResponse(Response response) {
return invocationOnMock -> {
ActionListener<Response> listener = (ActionListener<Response>) invocationOnMock.getArguments()[1];
listener.onResponse(response);
return null;
};
}
private static ClusterState createClusterState(Map<String, IndexMetadata> indices) {
return createClusterState(indices, Collections.emptyMap(), Collections.emptyMap());
}
private static ClusterState createClusterState(
Map<String, IndexMetadata> indices,
Map<String, IndexTemplateMetadata> legacyTemplates,
Map<String, ComposableIndexTemplate> composableTemplates
) {
return ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().indices(indices).templates(legacyTemplates).indexTemplates(composableTemplates).build())
.build();
}
private static IndexMetadata createIndexMetadata(String indexName) {
return createIndexMetadata(indexName, false);
}
private static IndexMetadata createIndexMetadataWithAlias(String indexName) {
return createIndexMetadata(indexName, true);
}
private static IndexTemplateMetadata createLegacyIndexTemplateMetaData(String templateName, List<String> patterns) {
return IndexTemplateMetadata.builder(templateName).patterns(patterns).build();
}
private static ComposableIndexTemplate createComposableIndexTemplateMetaData(String templateName, List<String> patterns, long version) {
return ComposableIndexTemplate.builder().indexPatterns(patterns).version(version).build();
}
private static IndexMetadata createIndexMetadata(String indexName, boolean withAlias) {
IndexMetadata.Builder builder = IndexMetadata.builder(indexName).settings(indexSettings(IndexVersion.current(), 1, 0));
if (withAlias) {
builder.putAlias(AliasMetadata.builder(TEST_INDEX_ALIAS).build());
}
return builder.build();
}
}
|
prepareCreate
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.