private static ClusterConnection createHConnection() throws IOException { ClusterConnection hc = Mockito.mock(ClusterConnection.class); NonceGenerator ng = Mockito.mock(NonceGenerator.class); Mockito.when(ng.getNonceGroup()).thenReturn(HConstants.NO_NONCE); Mockito.when(hc.getNonceGenerator()).thenReturn(ng); Mockito.when(hc.getConfiguration()).thenReturn(CONF); Mockito.when(hc.getConnectionConfiguration()).thenReturn(new ConnectionConfiguration(CONF)); setMockLocation(hc, GOOD_ROW, new RegionLocations(REGION_LOCATION)); setMockLocation(hc, BAD_ROW, new RegionLocations(REGION_LOCATION)); Mockito .when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Collections.singletonList(REGION_LOCATION)); return hc; }
case NORMAL: checkTableExists(tableName); for (HRegionLocation loc :connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) {
private ClusterConnection createHConnectionWithReplicas() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, hrls1); setMockLocation(hc, DUMMY_BYTES_2, hrls2); setMockLocation(hc, DUMMY_BYTES_3, hrls3); List<HRegionLocation> locations = new ArrayList<>(); for (HRegionLocation loc : hrls1.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls2.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls3.getRegionLocations()) { locations.add(loc); } Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(locations); return hc; }
@Override public void split(final TableName tableName, final byte[] splitPoint) throws IOException { checkTableExists(tableName); for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) { continue; } RegionInfo r = loc.getRegion(); // check for parents if (r.isSplitParent()) { continue; } // if a split point given, only split that particular region if (r.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID || (splitPoint != null && !r.containsRow(splitPoint))) { continue; } // call out to master to do split now splitRegionAsync(r, splitPoint); } }
private ClusterConnection createHConnection() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, new RegionLocations(loc1)); setMockLocation(hc, DUMMY_BYTES_2, new RegionLocations(loc2)); setMockLocation(hc, DUMMY_BYTES_3, new RegionLocations(loc3)); Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Arrays.asList(loc1, loc2, loc3)); setMockLocation(hc, FAILS, new RegionLocations(loc2)); return hc; }
break; case NORMAL: for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) {
ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(UTIL.getConfiguration()); ServerName oldMetaServer = conn.locateRegions(TableName.META_TABLE_NAME).get(0).getServerName(); ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName(); ServerName newMetaServer = conn.locateRegions(TableName.META_TABLE_NAME).get(0).getServerName(); assertTrue("The new meta server " + newMetaServer + " should be same with" + " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));
private static ClusterConnection createHConnection() throws IOException { ClusterConnection hc = Mockito.mock(ClusterConnection.class); NonceGenerator ng = Mockito.mock(NonceGenerator.class); Mockito.when(ng.getNonceGroup()).thenReturn(HConstants.NO_NONCE); Mockito.when(hc.getNonceGenerator()).thenReturn(ng); Mockito.when(hc.getConfiguration()).thenReturn(CONF); Mockito.when(hc.getConnectionConfiguration()).thenReturn(new ConnectionConfiguration(CONF)); setMockLocation(hc, GOOD_ROW, new RegionLocations(REGION_LOCATION)); setMockLocation(hc, BAD_ROW, new RegionLocations(REGION_LOCATION)); Mockito .when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Collections.singletonList(REGION_LOCATION)); return hc; }
case NORMAL: checkTableExists(tableName); for (HRegionLocation loc :connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) {
private static ClusterConnection createHConnectionWithReplicas() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, hrls1); setMockLocation(hc, DUMMY_BYTES_2, hrls2); setMockLocation(hc, DUMMY_BYTES_3, hrls3); List<HRegionLocation> locations = new ArrayList<>(); for (HRegionLocation loc : hrls1.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls2.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls3.getRegionLocations()) { locations.add(loc); } Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(locations); return hc; }
@Override public void split(final TableName tableName, final byte[] splitPoint) throws IOException { checkTableExists(tableName); for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) { continue; } RegionInfo r = loc.getRegion(); // check for parents if (r.isSplitParent()) { continue; } // if a split point given, only split that particular region if (r.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID || (splitPoint != null && !r.containsRow(splitPoint))) { continue; } // call out to master to do split now splitRegionAsync(r, splitPoint); } }
List<HRegionLocation> locations = hcon.locateRegions( org.apache.hadoop.hbase.TableName.valueOf(table.getPhysicalName().getBytes()));
private static ClusterConnection createHConnection() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, new RegionLocations(loc1)); setMockLocation(hc, DUMMY_BYTES_2, new RegionLocations(loc2)); setMockLocation(hc, DUMMY_BYTES_3, new RegionLocations(loc3)); Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Arrays.asList(loc1, loc2, loc3)); setMockLocation(hc, FAILS, new RegionLocations(loc2)); return hc; }
@Override public List<HRegionLocation> locateRegions(byte[] tableName, boolean useCache, boolean offlined) throws IOException { return wrappedConnection.locateRegions(tableName, useCache, offlined); }
break; case NORMAL: for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) {
@Override public List<HRegionLocation> locateRegions(TableName tableName) throws IOException { return wrappedConnection.locateRegions(tableName); }
@Override public List<HRegionLocation> locateRegions(TableName tableName, boolean useCache, boolean offlined) throws IOException { return wrappedConnection.locateRegions(tableName, useCache, offlined); }
@Override public List<HRegionLocation> locateRegions(byte[] tableName) throws IOException { return wrappedConnection.locateRegions(tableName); }
@Override public void split(final TableName tableName, final byte[] splitPoint) throws IOException { checkTableExists(tableName); for (HRegionLocation loc : connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) { continue; } RegionInfo r = loc.getRegion(); // check for parents if (r.isSplitParent()) { continue; } // if a split point given, only split that particular region if (r.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID || (splitPoint != null && !r.containsRow(splitPoint))) { continue; } // call out to master to do split now splitRegionAsync(r, splitPoint); } }
ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(UTIL.getConfiguration()); ServerName oldMetaServer = conn.locateRegions(TableName.META_TABLE_NAME).get(0).getServerName(); ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName(); ServerName newMetaServer = conn.locateRegions(TableName.META_TABLE_NAME).get(0).getServerName(); assertTrue("The new meta server " + newMetaServer + " should be same with" + " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));