admin
2021-03-18 b37275dba6b782bf3bb3817c4504f6cdef1bef7c
src/test/java/com/hxh/spring/test/SolrTest.java
@@ -1,41 +1,45 @@
package com.hxh.spring.test;
import com.yeshi.buwan.dao.HomeNoticeDao;
import com.yeshi.buwan.domain.SolrVideo;
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
import com.yeshi.buwan.domain.video.AlbumVideoMap;
import com.yeshi.buwan.dto.search.SolrResultDTO;
import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.manager.SolrAlbumDataManager;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService;
import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager;
import com.yeshi.buwan.service.manager.SolrCommonVideoDataManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.server.support.HttpSolrClientFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.security.Principal;
import java.util.Optional;
import java.util.Date;
import java.util.List;
//Optional@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations = {"classpath:spring.xml"})
//@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class SolrTest {
    @Resource
    private SolrAlbumDataManager solrDataManager;
    private SolrAlbumVideoDataManager solrDataManager;
    @Resource
    private SolrCommonVideoDataManager solrCommonVideoDataManager;
    @Resource
    private VideoInfoService videoInfoService;
    @Resource
    private HomeNoticeDao homeNoticeDao;
    @Resource
    private AlbumVideoMapService albumVideoMapService;
    @Test
    public void test1() {
@@ -51,14 +55,46 @@
    @Test
    public void addSolrAlbum() {
//        solrDataManager.syncAlbum("8224447");
        SolrClient solrClient = new HttpSolrClient.Builder("http://203.195.196.115:8983/solr").build();
        Credentials credentials = new UsernamePasswordCredentials("solr", "IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c=");
        HttpSolrClientFactory factory = new HttpSolrClientFactory(solrClient, null, null);
        SolrTemplate solrTemplate = new SolrTemplate(factory);
        solrTemplate.afterPropertiesSet();
        Optional<SolrVideo> solrVideoOptional = solrTemplate.getById("buwan_album", "8077525", SolrVideo.class);
       System.out.println(solrVideoOptional);
        solrDataManager.syncAllAlbum();
        System.out.println();
    }
    @Test
    public void syncSolrCommonVideo() {
//        solrCommonVideoDataManager.syncAllVideo();
    }
    @Resource
    private AlbumVideoMapDao albumVideoMapDao;
    @Test
    public void test2() {
        for(int i=0;i<100;i++) {
            Query query = new Query();
            query.addCriteria(Criteria.where("id").type(7));
            query.limit(100);
            List<AlbumVideoMap> list = albumVideoMapDao.findList(query);
            for (AlbumVideoMap map : list) {
                AlbumVideoMap newMap = new AlbumVideoMap();
                newMap.setVideoCount(map.getVideoCount());
                newMap.setRootVideoType(map.getRootVideoType());
                newMap.setVideoId(map.getVideoId());
                newMap.setCreateTime(new Date());
                newMap.setId(map.getVideoId());
                albumVideoMapDao.save(newMap);
                albumVideoMapDao.deleteByPrimaryKey(map.getId());
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }