mirror of https://github.com/apache/druid.git
Merge pull request #1201 from metamx/make-task-id-more-unique
randomize task ID to fix spurious test failure
This commit is contained in:
commit
e7d8f8034e
|
@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.metamx.common.guava.CloseQuietly;
|
||||
import com.metamx.common.parsers.ParseException;
|
||||
import com.metamx.emitter.EmittingLogger;
|
||||
|
@ -57,18 +58,36 @@ import org.joda.time.Period;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Random;
|
||||
|
||||
public class RealtimeIndexTask extends AbstractTask
|
||||
{
|
||||
private static final EmittingLogger log = new EmittingLogger(RealtimeIndexTask.class);
|
||||
private final static Random random = new Random();
|
||||
|
||||
private static String makeTaskId(FireDepartment fireDepartment)
|
||||
{
|
||||
return String.format(
|
||||
"index_realtime_%s_%d_%s",
|
||||
return makeTaskId(
|
||||
fireDepartment.getDataSchema().getDataSource(),
|
||||
fireDepartment.getTuningConfig().getShardSpec().getPartitionNum(),
|
||||
new DateTime().toString()
|
||||
new DateTime(),
|
||||
random.nextInt()
|
||||
);
|
||||
}
|
||||
|
||||
static String makeTaskId(String dataSource, int partitionNumber, DateTime timestamp, int randomBits)
|
||||
{
|
||||
final StringBuilder suffix = new StringBuilder(8);
|
||||
for(int i = 0; i < Ints.BYTES * 2; ++i) {
|
||||
suffix.append((char)('a' + ((randomBits >>> (i * 4)) & 0x0F)));
|
||||
}
|
||||
return String.format(
|
||||
"index_realtime_%s_%d_%s_%s",
|
||||
dataSource,
|
||||
partitionNumber,
|
||||
timestamp,
|
||||
suffix
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Metamarkets 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 io.druid.indexing.common.task;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RealtimeIndexTaskTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testMakeTaskId() throws Exception
|
||||
{
|
||||
Assert.assertEquals(
|
||||
"index_realtime_test_0_2015-01-02T00:00:00.000Z_abcdefgh",
|
||||
RealtimeIndexTask.makeTaskId("test", 0, new DateTime("2015-01-02"), 0x76543210)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue