Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Aug 12, 2023
1 parent ad8c998 commit eccb0bd
Show file tree
Hide file tree
Showing 12 changed files with 1,444 additions and 0 deletions.
62 changes: 62 additions & 0 deletions docs/spring/cs99931be8-38ba-11ee-84cd-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.huifer.fzjh.service;

import com.huifer.fzjh.bean.RequestEntity;
import com.huifer.fzjh.bean.ServerWeight;
import com.huifer.fzjh.exception.LoadBalanceException;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 负载均衡算法实现: 平滑加权算轮询法
*/
@Slf4j
public class SmoothnessWeightRandomLoadBalance extends AbstractLoadBalance {
private int count = -1;
private RequestEntity requestEntity;

private List<ServerWeight> serverWeights;

public SmoothnessWeightRandomLoadBalance(RequestEntity requestEntity, List<ServerWeight> serverWeights) {
super(requestEntity, serverWeights);
this.count = serverWeights.size();
this.requestEntity = requestEntity;
this.serverWeights = serverWeights;
}

private static String getServiceIndex(HashMap<Integer, ServerWeight> serverMap) {
ServerWeight maxWeightServer = null;
int allWeight = serverMap.values().stream().mapToInt(ServerWeight::getWeight).sum();
for (Map.Entry<Integer, ServerWeight> item : serverMap.entrySet()) {
ServerWeight currentServer = item.getValue();
if (maxWeightServer == null || currentServer.getCurrentWeight() > maxWeightServer.getCurrentWeight()) {
maxWeightServer = currentServer;
}
}
maxWeightServer.setCurrentWeight(maxWeightServer.getCurrentWeight() - allWeight);
for (Map.Entry<Integer, ServerWeight> item : serverMap.entrySet()) {
ServerWeight currentServer = item.getValue();
currentServer.setCurrentWeight(currentServer.getCurrentWeight() + currentServer.getWeight());
}
return maxWeightServer.getIp() + ":" + maxWeightServer.getPort();
}

@Override
public String loadBalance() {
if (count < 0) {
throw new LoadBalanceException("机器数量不能小于0");
}

HashMap<Integer, ServerWeight> serverHashMap = new HashMap<>();
for (int i = 0; i < serverWeights.size(); i++) {
serverHashMap.put(i, serverWeights.get(i));
}
String hostPost = getServiceIndex(serverHashMap);
log.info("当前请求信息={},负载均衡计算后的机器hostPost={}", requestEntity, hostPost);
return hostPost;
}


}
87 changes: 87 additions & 0 deletions docs/spring/cs99cf8560-38ba-11ee-84cd-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.ibatis.type;

import org.junit.jupiter.api.Test;

import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.*;

class TimeOnlyTypeHandlerTest extends BaseTypeHandlerTest {

private static final TypeHandler<Date> TYPE_HANDLER = new TimeOnlyTypeHandler();
private static final Date DATE = new Date();
private static final java.sql.Time SQL_TIME = new java.sql.Time(DATE.getTime());

@Override
@Test
public void shouldSetParameter() throws Exception {
TYPE_HANDLER.setParameter(ps, 1, DATE, null);
verify(ps).setTime(1, SQL_TIME);
}

@Override
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getTime("column")).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, "column"));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getTime("column")).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getTime(1)).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(rs, 1));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getTime(1)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, 1));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getTime(1)).thenReturn(SQL_TIME);
assertEquals(DATE, TYPE_HANDLER.getResult(cs, 1));
verify(cs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getTime(1)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(cs, 1));
verify(cs, never()).wasNull();
}

}
24 changes: 24 additions & 0 deletions docs/spring/cs9a0d490e-38ba-11ee-84cd-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2009-2015 the original author or authors.
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.ibatis.submitted.nested_query_cache;

import org.apache.ibatis.domain.blog.Author;

public interface AuthorMapper {

Author selectAuthor(int id);

}
90 changes: 90 additions & 0 deletions docs/spring/cs9a4c59be-38ba-11ee-84cd-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.huifer.rbac.entity.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.Version;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 角色和菜单的关系表
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "rbac.middle_role_menu")
public class MiddleRoleMenu implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;

@TableField(value = "role_id")
private Long roleId;

@TableField(value = "menu_id")
private Long menuId;

/**
* 创建时间
*/
@TableField(value = "create_time")
private LocalDateTime createTime;

/**
* 创建人
*/
@TableField(value = "create_user")
private Long createUser;

/**
* 修改时间
*/
@TableField(value = "update_time")
private LocalDateTime updateTime;

/**
* 修改人
*/
@TableField(value = "update_user")
private Long updateUser;

/**
* 版本
*/
@TableField(value = "version")
@Version
private Long version;

/**
* 是否删除标记
*/
@TableField(value = "is_delete")
@TableLogic
private Integer isDelete;

private static final long serialVersionUID = 1L;

public static final String COL_ID = "id";

public static final String COL_ROLE_ID = "role_id";

public static final String COL_MENU_ID = "menu_id";

public static final String COL_CREATE_TIME = "create_time";

public static final String COL_CREATE_USER = "create_user";

public static final String COL_UPDATE_TIME = "update_time";

public static final String COL_UPDATE_USER = "update_user";

public static final String COL_VERSION = "version";

public static final String COL_IS_DELETE = "is_delete";
}
27 changes: 27 additions & 0 deletions docs/spring/cs9a837426-38ba-11ee-84cc-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.huifer.idgen.my.service.populator;

import com.huifer.idgen.my.service.bean.Id;
import com.huifer.idgen.my.service.bean.IdMeta;

import java.util.concurrent.locks.ReentrantLock;

/**
* @author: wang
* @description:
*/
public class LockIdPropulator extends BasePopulator {

private ReentrantLock lock = new ReentrantLock();

@Override
public void populatorId(Id id, IdMeta idMeta) {
lock.lock();
try {
super.populatorId(id, idMeta);
} finally {
lock.unlock();
}
}


}
91 changes: 91 additions & 0 deletions docs/spring/cs9a87daa2-38ba-11ee-84cd-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.huifer.rmi.rpc.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
* <p>Title : MyTCPTransport </p>
* <p>Description : </p>
*
* @author huifer
* @date 2019-06-11
*/
public class MyTCPTransport {

private String host;
private int port;

public MyTCPTransport(String host, int port) {
this.host = host;
this.port = port;
}

/**
* 创建一个socket
*
* @return
*/
private Socket newSocket() {
Socket socket;
try {
socket = new Socket(this.host, this.port);
return socket;
} catch (Exception e) {

}
return null;
}

/**
* 远程信息交互
*
* @param rpcRequest
* @return
* @throws IOException
*/
public Object send(RpcRequest rpcRequest) throws IOException {
Socket socket = null;
try {
socket = newSocket();
ObjectOutputStream oos = new ObjectOutputStream(
socket.getOutputStream());

oos.writeObject(rpcRequest);
oos.flush();

ObjectInputStream ois = new ObjectInputStream(
socket.getInputStream()
);
Object o = ois.readObject();
ois.close();
oos.close();
return o;

} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (socket != null) {
socket.close();
}
}
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}
}
Loading

0 comments on commit eccb0bd

Please sign in to comment.