BLUR-ID:18 Created New Version of Files Signed-off-by: Aaron McCurry <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/bed15302 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/bed15302 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/bed15302 Branch: refs/heads/0.2-dev Commit: bed1530255f15aac460409a6ee572f0a48bab2a0 Parents: fc3ca94 Author: Gagan <[email protected]> Authored: Sat Nov 3 16:36:01 2012 +0530 Committer: Aaron McCurry <[email protected]> Committed: Sat Nov 3 21:59:58 2012 -0400 ---------------------------------------------------------------------- .../java/org/apache/blur/mr/BlurInputFormat.java | 110 +++++++++++ .../java/org/apache/blur/mr/BlurInputSplit.java | 145 +++++++++++++++ .../java/org/apache/blur/mr/BlurQuerySession.java | 109 +++++++++++ .../java/org/apache/blur/mr/BlurRecordReader.java | 111 +++++++++++ .../main/java/org/apache/blur/mr/BlurSession.java | 139 ++++++++++++++ .../org/apache/blur/mr/BlurInputFormatTest.java | 55 ++++++ .../org/apache/blur/mr/BlurInputSplitTest.java | 46 +++++ .../org/apache/blur/mr/BlurQuerySessionTest.java | 45 +++++ .../java/org/apache/blur/mr/BlurSessionTest.java | 61 ++++++ 9 files changed, 821 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputFormat.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputFormat.java b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputFormat.java new file mode 100644 index 0000000..7dc0190 --- /dev/null +++ b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputFormat.java @@ -0,0 +1,110 @@ +package org.apache.blur.mr; + +/** + * 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. + */ + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.blur.mapreduce.BlurMutate; +import org.apache.blur.mapreduce.BlurRecord; +import org.apache.blur.mapreduce.BlurReducer; +import org.apache.blur.thrift.BlurControllerServer; +import org.apache.blur.thrift.generated.BlurException; +import org.apache.blur.thrift.generated.QuerySession; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapreduce.InputFormat; +import org.apache.hadoop.mapreduce.InputSplit; +import org.apache.hadoop.mapreduce.Job; +import org.apache.hadoop.mapreduce.JobContext; +import org.apache.hadoop.mapreduce.RecordReader; +import org.apache.hadoop.mapreduce.TaskAttemptContext; +import org.apache.thrift.TException; + + +public class BlurInputFormat extends InputFormat<Text,BlurRecord>{ + private static Map<String,QuerySession> querySessionStore = new HashMap<String,QuerySession>(); + + @Override + public RecordReader<Text, BlurRecord> createRecordReader(InputSplit arg0, + TaskAttemptContext arg1) throws IOException, InterruptedException { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<InputSplit> getSplits(JobContext context) throws IOException, + InterruptedException { + QuerySession querySession = getReadQuerySession(context); + List<InputSplit> splits = new ArrayList<InputSplit>(); + BlurControllerServer controllerServer = new BlurControllerServer(); + // TODO Replace with API call to get Cluster name or implement in another way + String cluster = "test"; + try { + List<String> shardServerNames = controllerServer.shardServerList(cluster); + if (shardServerNames == null || shardServerNames.isEmpty()){ + throw new RuntimeException("Query not executing against any server"); + } + for (String shardServerName : shardServerNames){ + splits.add(new BlurInputSplit(shardServerName,new BlurQuerySession(querySession),0,Integer.MAX_VALUE)); + } + return splits; + } catch (BlurException e) { + throw new RuntimeException(" Problem while Getting results from Blur Controller " + e.stackTraceStr); + } catch (TException e) { + throw new RuntimeException(e.getMessage()); + } + } + + BlurControllerServer getBlurServerInstance() { + return new BlurControllerServer(); + } + + QuerySession getReadQuerySession(JobContext context){ + String queryId = context.getConfiguration().get("blur.query.id"); + QuerySession querySession = querySessionStore.get(queryId); + if(querySession == null){ + throw new RuntimeException("Query Object is Invalid or Null"); + } + return querySession; + } + public static Job configureJob(Configuration conf, QuerySession querySession) throws IOException{ + if(querySession == null){ + throw new IllegalArgumentException("Invalid read Session"); + } + querySessionStore.put(querySession.getQueryId(), querySession); + conf.set("blur.query.id",querySession.getQueryId()); + Job job = new Job(conf, "Blur Index Reader For query id : "+querySession.getQueryId()); + job.setReducerClass(BlurReducer.class); + job.setOutputKeyClass(BytesWritable.class); + job.setOutputValueClass(BlurMutate.class); + return job; + } + + public QuerySession getQuerySessionById(String querySessionId){ + return querySessionStore.get(querySessionId); + } + + public QuerySession removeQuerySessionFromSessionStoreById(String querySessionId){ + return querySessionStore.remove(querySessionId); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputSplit.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputSplit.java b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputSplit.java new file mode 100644 index 0000000..e1ab583 --- /dev/null +++ b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurInputSplit.java @@ -0,0 +1,145 @@ +package org.apache.blur.mr; + +/** + * 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. + */ +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.blur.mapreduce.IOUtil; +import org.apache.hadoop.io.Writable; +import org.apache.hadoop.mapreduce.InputSplit; + +public class BlurInputSplit extends InputSplit implements Writable, org.apache.hadoop.mapred.InputSplit { + + private String shardServerName; + private BlurQuerySession querySession; + private int startRecordNo; + private int lastRecordNo; + + public BlurInputSplit() { + querySession = new BlurQuerySession(); + } + + public BlurInputSplit(String shardServerName, BlurQuerySession querySession, int startRecordNo, int lastRecordNo) { + this.shardServerName = shardServerName; + this.querySession = querySession; + this.startRecordNo = startRecordNo; + this.lastRecordNo = lastRecordNo; + } + + @Override + public long getLength() { + return lastRecordNo - startRecordNo; + } + + @Override + public String[] getLocations() { + return new String[] {}; + } + + public String getShardServerName() { + return shardServerName; + } + + public void setShardServerName(String shardServerName) { + this.shardServerName = shardServerName; + } + + public BlurQuerySession getQuerySession() { + return querySession; + } + + public void setQuerySession(BlurQuerySession querySession) { + this.querySession = querySession; + } + + public int getStartRecordNo() { + return startRecordNo; + } + + public void setStartRecordNo(int startRecordNo) { + this.startRecordNo = startRecordNo; + } + + public int getLastRecordNo() { + return lastRecordNo; + } + + public void setLastRecordNo(int lastRecordNo) { + this.lastRecordNo = lastRecordNo; + } + + @Override + public void write(DataOutput out) throws IOException { + IOUtil.writeVInt(out, startRecordNo); + IOUtil.writeVInt(out, lastRecordNo); + IOUtil.writeString(out, shardServerName); + querySession.write(out); + } + + @Override + public void readFields(DataInput in) throws IOException { + startRecordNo = IOUtil.readVInt(in); + lastRecordNo = IOUtil.readVInt(in); + shardServerName = IOUtil.readString(in); + querySession.readFields(in); + } + + @Override + public String toString() { + return "shardServerName=" + shardServerName + ", startRecordNo=" + startRecordNo + + ", lastRecordNo=" + lastRecordNo + ", sessionId=" +querySession.getQueryId(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + lastRecordNo; + result = prime * result + ((querySession == null) ? 0 : querySession.hashCode()); + result = prime * result + ((shardServerName == null) ? 0 : shardServerName.hashCode()); + result = prime * result + startRecordNo; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BlurInputSplit other = (BlurInputSplit) obj; + if (lastRecordNo != other.lastRecordNo) + return false; + if (querySession == null) { + if (other.querySession != null) + return false; + } else if (!querySession.equals(other.querySession)) + return false; + if (shardServerName == null) { + if (other.shardServerName != null) + return false; + } else if (!shardServerName.equals(other.shardServerName)) + return false; + if (startRecordNo != other.startRecordNo) + return false; + return true; + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurQuerySession.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurQuerySession.java b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurQuerySession.java new file mode 100644 index 0000000..417b0d6 --- /dev/null +++ b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurQuerySession.java @@ -0,0 +1,109 @@ +package org.apache.blur.mr; + +/** + * 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. + */ + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.blur.mapreduce.IOUtil; +import org.apache.blur.thrift.generated.QuerySession; +import org.apache.hadoop.io.Writable; + +public class BlurQuerySession implements Writable{ + + private String queryId; + private BlurSession blurSession; + + public BlurQuerySession(){ + queryId = new String(); + blurSession = new BlurSession(); + } + + public BlurQuerySession(QuerySession querySession){ + queryId = querySession.getQueryId(); + blurSession = new BlurSession(querySession.getSession()); + } + + + public String getQueryId() { + return queryId; + } + + + public void setQueryId(String querySessionId) { + this.queryId = querySessionId; + } + + + public BlurSession getBlurSession() { + return blurSession; + } + + + public void setBlurSession(BlurSession blurSession) { + this.blurSession = blurSession; + } + + + @Override + public void write(DataOutput out) throws IOException { + IOUtil.writeString(out, queryId); + blurSession.write(out); + } + + @Override + public void readFields(DataInput in) throws IOException { + queryId = IOUtil.readString(in); + blurSession.readFields(in); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((blurSession == null) ? 0 : blurSession.hashCode()); + result = prime * result + ((queryId == null) ? 0 : queryId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BlurQuerySession other = (BlurQuerySession) obj; + if (blurSession == null) { + if (other.blurSession != null) + return false; + } else if (!blurSession.equals(other.blurSession)) + return false; + if (queryId == null) { + if (other.queryId != null) + return false; + } else if (!queryId.equals(other.queryId)) + return false; + return true; + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurRecordReader.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurRecordReader.java b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurRecordReader.java new file mode 100644 index 0000000..23fe61d --- /dev/null +++ b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurRecordReader.java @@ -0,0 +1,111 @@ +package org.apache.blur.mr; + +/** + * 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. + */ +import java.io.IOException; + +import org.apache.blur.mapreduce.BlurRecord; +import org.apache.blur.mapreduce.lib.BlurInputSplit; +import org.apache.blur.mapreduce.lib.Utils; +import org.apache.blur.store.hdfs.HdfsDirectory; +import org.apache.blur.utils.RowDocumentUtil; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.InputSplit; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.RecordReader; +import org.apache.lucene.document.Document; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.IndexCommit; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.store.Directory; + + +public abstract class BlurRecordReader implements RecordReader<Text, BlurRecord> { + + public BlurRecordReader(InputSplit split, JobConf job) throws IOException { + } + +// private IndexReader reader; +// private Directory directory; +// private int startingDocId; +// private int endingDocId; +// private int position; +// +// public BlurRecordReader(InputSplit split, JobConf job) throws IOException { +// BlurInputSplit blurSplit = (BlurInputSplit) split; +// Path path = blurSplit.getIndexPath(); +// String segmentName = blurSplit.getSegmentName(); +// startingDocId = blurSplit.getStartingDocId(); +// endingDocId = blurSplit.getEndingDocId(); +// directory = new HdfsDirectory(path); +// +// IndexCommit commit = Utils.findLatest(directory); +// reader = Utils.openSegmentReader(directory, commit, segmentName, Utils.getTermInfosIndexDivisor(job)); +// int maxDoc = reader.maxDoc(); +// if (endingDocId >= maxDoc) { +// endingDocId = maxDoc - 1; +// } +// position = startingDocId - 1; +// } +// +// @Override +// public boolean next(Text key, BlurRecord value) throws IOException { +// do { +// position++; +// if (position > endingDocId) { +// return false; +// } +// } while (reader.isDeleted(position)); +// readDocument(key, value); +// return true; +// } +// +// private void readDocument(Text rowid, BlurRecord record) throws CorruptIndexException, IOException { +// Document document = reader.document(position); +// record.reset(); +// rowid.set(RowDocumentUtil.readRecord(document, record)); +// } +// +// @Override +// public Text createKey() { +// return new Text(); +// } +// +// @Override +// public BlurRecord createValue() { +// return new BlurRecord(); +// } +// +// @Override +// public long getPos() throws IOException { +// return position; +// } +// +// @Override +// public void close() throws IOException { +// reader.close(); +// directory.close(); +// } +// +// @Override +// public float getProgress() throws IOException { +// int total = endingDocId - startingDocId; +// return (float) position / (float) total; +// } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurSession.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurSession.java b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurSession.java new file mode 100644 index 0000000..57aa1fb --- /dev/null +++ b/src/blur-mapred/src/main/java/org/apache/blur/mr/BlurSession.java @@ -0,0 +1,139 @@ +package org.apache.blur.mr; + +/** + * 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. + */ + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.blur.mapreduce.IOUtil; +import org.apache.blur.thrift.generated.Session; +import org.apache.hadoop.io.MapWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.Writable; + +public class BlurSession implements Writable { + + private String sessionId; + private MapWritable properties; + + public BlurSession() { + sessionId = new String(); + properties = new MapWritable(); + } + + public BlurSession(Session session) { + sessionId = session.getSessionId(); + properties = new MapWritable(); + convertMapToWritableMap(session.getProperties()); + } + + public String getSessionId() { + return sessionId; + } + + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + public MapWritable getProperties() { + return properties; + } + + public void setProperties(MapWritable properties) { + this.properties = properties; + } + + private void convertMapToWritableMap(Map<String, String> sessionProperties) { + Set<Map.Entry<String, String>> mapEntries = sessionProperties.entrySet(); + for (Map.Entry<String, String> entry : mapEntries) { + properties.put(new Text(entry.getKey()), new Text(entry.getValue())); + } + } + + private Map<String, String> convertWritableMapToHashMap( + MapWritable sessionProperties) { + Map<String, String> javaMap = new HashMap<String, String>(); + if (! sessionProperties.isEmpty()) { + Set<Map.Entry<Writable, Writable>> mapEntries = sessionProperties + .entrySet(); + for (Map.Entry<Writable, Writable> entry : mapEntries) { + javaMap.put(((Text) entry.getKey()).toString(), + ((Text) entry.getValue()).toString()); + } + } + return javaMap; + } + + @Override + public void write(DataOutput out) throws IOException { + IOUtil.writeString(out, sessionId); + properties.write(out); + } + + @Override + public void readFields(DataInput in) throws IOException { + sessionId = IOUtil.readString(in); + properties.readFields(in); + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((properties == null) ? 0 : properties.hashCode()); + result = prime * result + ((sessionId == null) ? 0 : sessionId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + Map<String,String> thisMap; + Map<String,String> otherMap; + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BlurSession other = (BlurSession) obj; + if (properties == null) { + if (other.properties != null) + return false; + } else{ + thisMap = convertWritableMapToHashMap(properties); + otherMap = convertWritableMapToHashMap(other.properties); + if(! thisMap.equals(otherMap)) + return false; + } + if (sessionId == null) { + if (other.sessionId != null) + return false; + } else if (!sessionId.equals(other.sessionId)) + return false; + return true; + } + + + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputFormatTest.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputFormatTest.java b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputFormatTest.java new file mode 100644 index 0000000..8e7d00f --- /dev/null +++ b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputFormatTest.java @@ -0,0 +1,55 @@ +package org.apache.blur.mr; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.blur.thrift.generated.QuerySession; +import org.apache.blur.thrift.generated.Session; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.mapreduce.Job; +import org.junit.Before; +import org.junit.Test; + + +public class BlurInputFormatTest { + + private QuerySession querySession; + + + private Job job; + + @Before + public void setup() throws IOException{ + String queryId = "BB2410XXY"; + String sessionId = "AA0231XZ"; + Map<String,String> properties = new HashMap<String,String>(); + properties.put("SampleKey1", "SampleValue1"); + properties.put("SampleKey2", "SampleValue2"); + querySession = new QuerySession(new Session(sessionId, properties), queryId); + job = BlurInputFormat.configureJob(new Configuration(), querySession); + } + + @Test + public void testReadQuerySession(){ + BlurInputFormat blurInputFormat = new BlurInputFormat(); + QuerySession querySessionTest = blurInputFormat.getReadQuerySession(job); + assertEquals(querySession.getQueryId(),querySessionTest.getQueryId()); + assertEquals(querySessionTest.getSession().getPropertiesSize(), querySession.getSession().getPropertiesSize()); + } + + /*@Test + public void testGetSplits() throws BlurException, TException, IOException, InterruptedException{ + String[] shardServers = {"ShardServer1"}; + BlurInputFormat blurInputFormat = new BlurInputFormat(); + controllerServer.setClusterStatus(clusterStatus); + Mockito.when(clusterStatus.getShardServerList(Mockito.anyString())).thenReturn(Arrays.asList(shardServers)); + + List<InputSplit> splits = blurInputFormat.getSplits(job); + + assertTrue(splits.size() > 0); + assertEquals(((BlurInputSplit)splits.get(0)).getShardServerName(), "ShardServer1"); + }*/ +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputSplitTest.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputSplitTest.java b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputSplitTest.java new file mode 100644 index 0000000..e38a702 --- /dev/null +++ b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurInputSplitTest.java @@ -0,0 +1,46 @@ +package org.apache.blur.mr; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.blur.thrift.generated.QuerySession; +import org.apache.blur.thrift.generated.Session; +import org.apache.hadoop.io.DataInputBuffer; +import org.apache.hadoop.io.DataOutputBuffer; +import org.junit.Before; +import org.junit.Test; + +public class BlurInputSplitTest { + + private QuerySession querySession; + + private BlurInputSplit blurInputSplitBefore; + @Before + public void setup(){ + String queryId = "BB2410XXY"; + String sessionId = "AA0231XZ"; + Map<String,String> properties = new HashMap<String,String>(); + properties.put("SampleKey1", "SampleValue1"); + properties.put("SampleKey2", "SampleValue2"); + querySession = new QuerySession(new Session(sessionId, properties), queryId); + blurInputSplitBefore = new BlurInputSplit("ShardServer1",new BlurQuerySession(querySession), 0, Integer.MAX_VALUE); + } + + @Test + public void testBlurInputSplitWritable() throws IOException{ + DataOutputBuffer dob = new DataOutputBuffer(); + blurInputSplitBefore.write(dob); + + DataInputBuffer dib = new DataInputBuffer(); + dib.reset(dob.getData(), dob.getLength()); + + BlurInputSplit blurInputSplitAfter = new BlurInputSplit(); + blurInputSplitAfter.readFields(dib); + + assertEquals(blurInputSplitBefore.getLength(), blurInputSplitAfter.getLength()); + assertEquals(blurInputSplitBefore.getShardServerName(), blurInputSplitAfter.getShardServerName()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurQuerySessionTest.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurQuerySessionTest.java b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurQuerySessionTest.java new file mode 100644 index 0000000..fbd0364 --- /dev/null +++ b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurQuerySessionTest.java @@ -0,0 +1,45 @@ +package org.apache.blur.mr; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.blur.thrift.generated.QuerySession; +import org.apache.blur.thrift.generated.Session; +import org.apache.hadoop.io.DataInputBuffer; +import org.apache.hadoop.io.DataOutputBuffer; +import org.junit.Test; + +public class BlurQuerySessionTest { + + private BlurQuerySession blurQuerySessionBefore; + + private void createBlurQuerySessionBeforeObject(){ + String queryId = "BB2410XXY"; + String sessionId = "AA0231XZ"; + Map<String,String> properties = new HashMap<String,String>(); + properties.put("SampleKey1", "SampleValue1"); + properties.put("SampleKey2", "SampleValue2"); + blurQuerySessionBefore = new BlurQuerySession(new QuerySession(new Session(sessionId, properties), queryId)); + } + + @Test + public void testBlurSessionWritable() throws IOException{ + createBlurQuerySessionBeforeObject(); + + DataOutputBuffer dob = new DataOutputBuffer(); + blurQuerySessionBefore.write(dob); + + DataInputBuffer dib = new DataInputBuffer(); + dib.reset(dob.getData(), dob.getLength()); + + BlurQuerySession blurQuerySessionAfter = new BlurQuerySession(); + blurQuerySessionAfter.readFields(dib); + + assertEquals(blurQuerySessionBefore.getQueryId(), blurQuerySessionAfter.getQueryId()); + assertEquals(blurQuerySessionBefore.getBlurSession().getSessionId(), blurQuerySessionAfter.getBlurSession().getSessionId()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/bed15302/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurSessionTest.java ---------------------------------------------------------------------- diff --git a/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurSessionTest.java b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurSessionTest.java new file mode 100644 index 0000000..577a9ea --- /dev/null +++ b/src/blur-mapred/src/test/java/org/apache/blur/mr/BlurSessionTest.java @@ -0,0 +1,61 @@ +package org.apache.blur.mr; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.blur.thrift.generated.Session; +import org.apache.hadoop.io.DataInputBuffer; +import org.apache.hadoop.io.DataOutputBuffer; +import org.junit.Before; +import org.junit.Test; + +public class BlurSessionTest { + + private BlurSession blurSessionBefore; + private BlurSession blurSession; + + @Before + public void createBlurSessionBeforeObject(){ + String sessionId = "AA0231XZ"; + Map<String,String> properties = new HashMap<String,String>(); + properties.put("SampleKey1", "SampleValue1"); + properties.put("SampleKey2", "SampleValue2"); + blurSession = new BlurSession(new Session(sessionId, properties)); + + Map<String,String> properties1 = new HashMap<String,String>(); + properties.put("SampleKey3", "SampleValue3"); + properties.put("SampleKey4", "SampleValue4"); + + blurSessionBefore = new BlurSession(new Session(sessionId, properties1)); + } + + @Test + public void testBlurSessionWritable() throws IOException{ + + DataOutputBuffer dob = new DataOutputBuffer(); + blurSessionBefore.write(dob); + + DataInputBuffer dib = new DataInputBuffer(); + dib.reset(dob.getData(), dob.getLength()); + + BlurSession blurSessionAfter = new BlurSession(); + blurSessionAfter.readFields(dib); + + assertEquals(blurSessionBefore.getSessionId(),blurSessionAfter.getSessionId()); + assertEquals(blurSessionBefore.getProperties().size(), blurSessionAfter.getProperties().size()); + assertEquals(blurSessionBefore.getProperties().get("SampleKey1"), blurSessionAfter.getProperties().get("SampleKey1")); + } + + @Test + public void testEquals(){ + assertTrue(blurSession.equals(blurSession)); + assertFalse(blurSession.equals(blurSessionBefore)); + + } +}
