Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public ConfigPhysicalPlanType getType() {
return this.type;
}

public short getPlanTypeId() {
return type.getPlanType();
}

@Override
public ByteBuffer serializeToByteBuffer() {
try (final PublicBAOS byteArrayOutputStream = new PublicBAOS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
import org.apache.iotdb.confignode.consensus.request.write.template.ExtendSchemaTemplatePlan;

public abstract class ConfigPhysicalPlanVisitor<R, C> {
private final TimechoConfigPhysicalPlanVisitor<R, C> timechoVisitor =
new TimechoConfigPhysicalPlanVisitor<>();

public R process(final ConfigPhysicalPlan plan, final C context) {
if (isTimechoPlan(plan)) {
return timechoVisitor.process(plan, context);
}
switch (plan.getType()) {
case CreateDatabase:
return visitCreateDatabase((DatabaseSchemaPlan) plan, context);
Expand Down Expand Up @@ -207,6 +213,10 @@ public R process(final ConfigPhysicalPlan plan, final C context) {
}
}

protected boolean isTimechoPlan(final ConfigPhysicalPlan plan) {
return plan.getPlanTypeId() < 0;
}

/** Top Level Description */
public abstract R visitPlan(final ConfigPhysicalPlan plan, final C context);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.iotdb.confignode.consensus.request;

public class TimechoConfigPhysicalPlanVisitor<R, C> {

public R process(final ConfigPhysicalPlan plan, final C context) {
return visitPlan(plan, context);
}

public R visitPlan(final ConfigPhysicalPlan plan, final C context) {
throw new UnsupportedOperationException(
String.format(
"Timecho config physical plan is not supported in Apache IoTDB: %s",
plan.getPlanTypeId()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.iotdb.confignode.consensus.request;

import org.junit.Assert;
import org.junit.Test;

import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

public class ConfigPhysicalPlanVisitorTest {

@Test
public void testNegativePlanTypeIdIsDispatchedToTimechoVisitor() {
final boolean[] openSourceVisitorVisited = new boolean[] {false};
final ConfigPhysicalPlanVisitor<String, Void> visitor =
new ConfigPhysicalPlanVisitor<String, Void>() {
@Override
public String visitPlan(final ConfigPhysicalPlan plan, final Void context) {
openSourceVisitorVisited[0] = true;
return "open-source";
}
};

try {
visitor.process(new NegativePlan(), null);
Assert.fail("Expected timecho plan to be dispatched to the placeholder visitor");
} catch (final UnsupportedOperationException e) {
Assert.assertFalse(openSourceVisitorVisited[0]);
Assert.assertTrue(e.getMessage().contains("-1"));
}
}

private static class NegativePlan extends ConfigPhysicalPlan {

private NegativePlan() {
super(ConfigPhysicalPlanType.TestOnly);
}

@Override
public short getPlanTypeId() {
return -1;
}

@Override
protected void serializeImpl(final DataOutputStream stream) throws IOException {
stream.writeShort(getPlanTypeId());
}

@Override
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
// Nothing to deserialize for the test-only placeholder plan.
}
}
}
Loading