-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from eincs/fix-withouttx-bug
Fix bug that getValue returns null when without transaction context.
- Loading branch information
Showing
2 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/kr/co/vcnc/haeinsa/WithOutTransactionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (C) 2013-2015 VCNC Inc. | ||
* | ||
* 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 kr.co.vcnc.haeinsa; | ||
|
||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class WithOutTransactionTest extends HaeinsaTestBase { | ||
|
||
@Test | ||
public void testGet() throws Exception { | ||
final HaeinsaTransactionManager tm = context().getTransactionManager(); | ||
final HaeinsaTableIface testTable = context().getHaeinsaTableIface("test"); | ||
|
||
byte[] row = Bytes.toBytes("row"); | ||
byte[] family = Bytes.toBytes("data"); | ||
byte[] col1 = Bytes.toBytes("col1"); | ||
byte[] col2 = Bytes.toBytes("col2"); | ||
|
||
// Insert data wih transaction | ||
{ | ||
HaeinsaTransaction tx = tm.begin(); | ||
HaeinsaPut put = new HaeinsaPut(row); | ||
put.add(family, col1, Bytes.toBytes("value1")); | ||
testTable.put(tx, put); | ||
put = new HaeinsaPut(row); | ||
put.add(family, col2, Bytes.toBytes("value2")); | ||
testTable.put(tx, put); | ||
tx.commit(); | ||
} | ||
// Get with transaction | ||
{ | ||
HaeinsaTransaction tx = tm.begin(); | ||
HaeinsaGet get = new HaeinsaGet(row); | ||
get.addFamily(family); | ||
HaeinsaResult result = testTable.get(tx, get); | ||
tx.commit(); | ||
|
||
byte[] value1 = result.getValue(family, col1); | ||
byte[] value2 = result.getValue(family, col2); | ||
|
||
Assert.assertEquals(result.containsColumn(family, col1), true); | ||
Assert.assertEquals(result.containsColumn(family, col2), true); | ||
Assert.assertEquals(value1, Bytes.toBytes("value1")); | ||
Assert.assertEquals(value2, Bytes.toBytes("value2")); | ||
} | ||
// Get without transaction | ||
{ | ||
HaeinsaGet get = new HaeinsaGet(row); | ||
get.addFamily(family); | ||
HaeinsaResult result = testTable.get(null, get); | ||
|
||
byte[] value1 = result.getValue(family, col1); | ||
byte[] value2 = result.getValue(family, col2); | ||
|
||
Assert.assertEquals(result.containsColumn(family, col1), true); | ||
Assert.assertEquals(result.containsColumn(family, col2), true); | ||
Assert.assertEquals(value1, Bytes.toBytes("value1")); | ||
Assert.assertEquals(value2, Bytes.toBytes("value2")); | ||
} | ||
} | ||
} |